Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions App.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ export default class App extends React.Component {
data={data}
width={width}
height={height}
yAxisLabel={'$'}
chartConfig={chartConfig}
style={graphStyle}
onDataPointClick={({value, getColor}) =>
Expand All @@ -141,6 +142,7 @@ export default class App extends React.Component {
width={width}
height={height}
data={data}
yAxisLabel={'$'}
chartConfig={chartConfig}
style={graphStyle}
/>
Expand All @@ -160,6 +162,7 @@ export default class App extends React.Component {
data={data}
width={width}
height={height}
yAxisLabel={'$'}
chartConfig={chartConfig}
style={graphStyle}
/>
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import {
}}
width={Dimensions.get('window').width} // from react-native
height={220}
yAxisLabel={'$'}
chartConfig={{
backgroundColor: '#e26a00',
backgroundGradientFrom: '#fb8c00',
Expand Down Expand Up @@ -120,6 +121,7 @@ const data = {
| withShadow | boolean | Show shadow for line - default: True |
| withInnerLines | boolean | Show inner dashed lines - default: True |
| withOuterLines | boolean | Show outer dashed lines - default: True |
| yAxisLabel | string | Prepend text to horizontal labels -- default: '' |
| chartConfig | Object | Configuration object for the chart, see example config object above |
|decorator | Function | This function takes a [whole bunch](https://github.com/indiespirit/react-native-chart-kit/blob/master/src/line-chart.js#L266) of stuff and can render extra elements, such as data point info or additional markup. |
|onDataPointClick| Function| Callback that takes `{value, dataset, getColor}`|
Expand Down Expand Up @@ -184,6 +186,7 @@ const data = {
data={data}
width={screenWidth}
height={220}
yAxisLabel={'$'}
chartConfig={chartConfig}
/>
```
Expand All @@ -193,6 +196,7 @@ const data = {
| data | Object | Data for the chart - see example above |
| width | Number | Width of the chart, use 'Dimensions' library to get the width of your screen for responsive |
| height | Number | Height of the chart |
| yAxisLabel | string | Prepend text to horizontal labels -- default: '' |
| chartConfig | Object | Configuration object for the chart, see example config in the beginning of this file |

## Pie chart
Expand Down
15 changes: 13 additions & 2 deletions src/abstract-chart.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,19 @@ class AbstractChart extends Component {

renderHorizontalLabels = config => {
const { count, data, height, paddingTop, paddingRight, yLabelsOffset = 12 } = config
var decimalPlaces = (this.props.chartConfig.decimalPlaces !== undefined) ? this.props.chartConfig.decimalPlaces : 2;
const decimalPlaces = this.props.chartConfig.decimalPlaces || 2;
const yAxisLabel = this.props.yAxisLabel || ''

return [...new Array(count)].map((_, i) => {
let yLabel;

if(count === 1){
yLabel = `${yAxisLabel}${data[0].toFixed(decimalPlaces)}`
}else {
const label = (this.calcScaler(data) / (count - 1)) * i + Math.min(...data)
yLabel = `${yAxisLabel}${label.toFixed(decimalPlaces)}`
}

return (
<Text
key={Math.random()}
Expand All @@ -57,7 +68,7 @@ class AbstractChart extends Component {
y={(height * 3 / 4) - ((height - paddingTop) / count * i) + 12}
fontSize={12}
fill={this.props.chartConfig.color(0.5)}
>{count === 1 ? data[0].toFixed(decimalPlaces) : ((this.calcScaler(data) / (count - 1)) * i + Math.min(...data)).toFixed(decimalPlaces)}
>{yLabel}
</Text>
)
})
Expand Down