forked from JesperLekland/react-native-svg-charts-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
horizontal-with-axis.js
62 lines (55 loc) · 1.69 KB
/
horizontal-with-axis.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React from 'react'
import { View } from 'react-native'
import { BarChart, Grid, YAxis } from 'react-native-svg-charts'
import * as scale from 'd3-scale'
class HorizontaBarChartWithYAxis extends React.PureComponent {
render() {
const data = [
{
value: 50,
label: 'One',
},
{
value: 10,
label: 'Two',
},
{
value: 40,
label: 'Three',
},
{
value: 95,
label: 'Four',
},
{
value: 85,
label: 'Five',
},
]
return (
<View style={{ flexDirection: 'row', height: 200, paddingVertical: 16 }}>
<YAxis
data={data}
yAccessor={({ index }) => index}
scale={scale.scaleBand}
contentInset={{ top: 10, bottom: 10 }}
spacing={0.2}
formatLabel={(_, index) => data[ index ].label}
/>
<BarChart
style={{ flex: 1, marginLeft: 8 }}
data={data}
horizontal={true}
yAccessor={({ item }) => item.value}
svg={{ fill: 'rgba(134, 65, 244, 0.8)' }}
contentInset={{ top: 10, bottom: 10 }}
spacing={0.2}
gridMin={0}
>
<Grid direction={Grid.Direction.VERTICAL}/>
</BarChart>
</View>
)
}
}
export default HorizontaBarChartWithYAxis