Description:
The React-native-statistic-charts component leverages the power of React Native SVG to render beautiful, interactive charts that will make your app’s data pop.
It provides a wide selection of chart types – from line and bar charts to pie, donut and radar charts – with smooth animations and tooltip support.
How to use it:
1. Install the component with NPM.
# Yarn $ yarn add react-native-svg react-native-statistic-charts # NPM $ npm install react-native-svg react-native-statistic-charts
2. Create a line chart.
import React from 'react'
import { View, Dimensions } from 'react-native'
import { Chart, Axis, Tooltip, Line, ScaleType } from 'react-native-statistic-charts'
// const data = { date: sring, value: number }[]
export default () => (
<View>
<Chart
data={data}
scale={{
date: { type: ScaleType.TimeCategory },
value: { type: ScaleType.Linear, tickCount: 6 },
}}
>
<Axis field="date" />
<Axis field="value" lineStyle={{ strokeWidth: 0 }} tickLineStyle={{ strokeWidth: 0 }} grid />
<Line position="date*value" />
<Tooltip
crosshair
crosshairsType="x"
crosshairStyle={{ strokeColor: 'orange', strokeWidth: 2, strokeStyle: 'solid' }}
sticky
/>
</Chart>
</View>
)3. Create a bar (column) chart.
import React from 'react'
import { View, Dimensions } from 'react-native'
import { Chart, Axis, Tooltip, Interval, ScaleType } from 'react-native-statistic-charts'
// const data = { date: sring, value: number }[]
export default () => (
<View>
<Chart
data={data}
>
<Axis field="date" lineStyle={{ strokeColor: '#aaa' }} tickLineStyle={{ strokeWidth: 0 }} tickCount={8} />
<Axis
field="value"
lineStyle={{ strokeWidth: 0 }}
tickLineStyle={{ strokeWidth: 0 }}
grid
gridLineStyle={{ strokeStyle: 'dashed', dashedStyle: [2] }}
labelStyle={{ offset: 6 }}
/>
<Interval
position="date*value"
size={10}
groupBy="country"
color={{ field: 'value', value: record => (record['value'] > 0 ? 'green' : 'red') }}
/>
<Tooltip
crosshair
crosshairsType="x"
crosshairStyle={{ strokeColor: 'orange', strokeWidth: 1, strokeStyle: 'solid' }}
sticky
label={false}
/>
</Chart>
</View>
)4. Create an area chart.
import React from 'react'
import { View, Dimensions } from 'react-native'
import { Chart, Axis, Tooltip, Area, ScaleType } from 'react-native-statistic-charts'
// const data = { date: sring, value: number }[]
export default () => (
<Chart
data={this.data}
scale={{ date: { type: ScaleType.TimeCategory } }}
>
<Axis
field="date"
tickCount={3}
lineStyle={{ strokeColor: '#aaa' }}
tickLineStyle={{ strokeColor: '#ccc' }}
/>
<Axis
field="value"
grid
lineStyle={{ strokeWidth: 0 }}
tickLineStyle={{ strokeWidth: 0 }}
gridLineStyle={{ strokeStyle: 'dashed', dashedStyle: [2] }}
/>
<Line position="date*value" color={{ value: 'orange' }} />
<Area
position="date*value"
color='orange'
style={{ fill: 'linear-gradient(90deg, orange 0%, #FFFFFF 100%)' }}
/>
<Tooltip
crosshair
crosshairsType="x"
crosshairStyle={{ strokeColor: this.state.color, strokeWidth: 1, strokeStyle: 'solid' }}
sticky
/>
</Chart>
)5. Create a donut (pie) chart.
import React from 'react'
import { View, Dimensions } from 'react-native'
import { Chart, Axis, Tooltip, Interval, ScaleType } from 'react-native-statistic-charts'
// const data = { name: sring, percent: number, a: '1' }[]
export default () => (
<Chart
data={data}
coord={{ transposed: true, type: 'polar', radius: 1, innerRadius: 0.55 }}
>
<Interval
position="a*percent"
adjust="stack"
groupBy="name"
color={{
value: [
'#EDA500',
'#F97B0D',
'#EE2C4C',
'#BF3D39',
'#803F62',
'#40428A',
'#0046AB',
'#0079A5',
'#26AA99',
'#7EA84D',
],
}}
itemStyle={{ borderWidth: 3, borderColor: '#fff' }}
/>
</Chart>
)6. Create a radar chart.
import React from 'react'
import { View, Dimensions } from 'react-native'
import { Chart, Axis, Tooltip, Line, ScaleType } from 'react-native-statistic-charts'
// const data = { date: sring, value: number }[]
export default () => (
<Chart
data={this.data}
coord={{ type: 'polar' }}
scale={{ date: { type: ScaleType.TimeCategory, range: [0, 14 / 16] } }}
>
<Axis
tickCount={8}
field="date"
lineStyle={{ strokeColor: '#aaa' }}
tickLineStyle={{ strokeColor: '#ccc' }}
labelStyle={{ offset: 10 }}
grid
/>
<Axis field="value" lineStyle={{ strokeColor: '#aaa' }} tickLineStyle={{ strokeColor: '#ccc' }} grid />
<Line position="date*value" size={2} groupBy="name" />
<Tooltip
crosshair
crosshairsType="x"
crosshairStyle={{ strokeColor: 'orange', strokeWidth: 2, strokeStyle: 'solid' }}
sticky
/>
</Chart>
)