forked from JesperLekland/react-native-svg-charts-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
with-y-axis.js
74 lines (68 loc) · 2.3 KB
/
with-y-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
63
64
65
66
67
68
69
70
71
72
73
74
import React from 'react'
import { StackedAreaChart, YAxis, Grid } from 'react-native-svg-charts'
import * as shape from 'd3-shape'
import { View } from 'react-native'
class AreaStackWithAxisExample extends React.PureComponent {
render() {
const data = [
{
month: new Date(2015, 0, 1),
apples: 3840,
bananas: 1920,
cherries: 960,
dates: 400,
},
{
month: new Date(2015, 1, 1),
apples: 1600,
bananas: 1440,
cherries: 960,
dates: 400,
},
{
month: new Date(2015, 2, 1),
apples: 640,
bananas: 960,
cherries: 3640,
dates: 400,
},
{
month: new Date(2015, 3, 1),
apples: 3320,
bananas: 480,
cherries: 640,
dates: 400,
},
]
const colors = [ 'rgb(138, 0, 230, 0.8)', 'rgb(173, 51, 255, 0.8)', 'rgb(194, 102, 255, 0.8)', 'rgb(214, 153, 255, 0.8)' ]
const keys = [ 'apples', 'bananas', 'cherries', 'dates' ]
return (
<View style={ { flexDirection: 'row', height: 200 } }>
<StackedAreaChart
style={ { flex: 1 } }
contentInset={ { top: 10, bottom: 10 } }
data={ data }
keys={ keys }
colors={ colors }
curve={ shape.curveNatural }
>
<Grid/>
</StackedAreaChart>
<YAxis
style={ { position: 'absolute', top: 0, bottom: 0 }}
data={ StackedAreaChart.extractDataPoints(data, keys) }
contentInset={ { top: 10, bottom: 10 } }
svg={ {
fontSize: 8,
fill: 'white',
stroke: 'black',
strokeWidth: 0.1,
alignmentBaseline: 'baseline',
baselineShift: '3',
} }
/>
</View>
)
}
}
export default AreaStackWithAxisExample