forked from JesperLekland/react-native-svg-charts-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboth-axes.js
52 lines (44 loc) · 2.02 KB
/
both-axes.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
import React from 'react'
import { Grid, LineChart, XAxis, YAxis } from 'react-native-svg-charts'
import { View } from 'react-native'
class AxesExample extends React.PureComponent {
render() {
const data = [ 50, 10, 40, 95, -4, -24, 85, 91, 35, 53, -53, 24, 50, -20, -80 ]
const axesSvg = { fontSize: 10, fill: 'grey' };
const verticalContentInset = { top: 10, bottom: 10 }
const xAxisHeight = 30
// Layout of an x-axis together with a y-axis is a problem that stems from flexbox.
// All react-native-svg-charts components support full flexbox and therefore all
// layout problems should be approached with the mindset "how would I layout regular Views with flex in this way".
// In order for us to align the axes correctly we must know the height of the x-axis or the width of the x-axis
// and then displace the other axis with just as many pixels. Simple but manual.
return (
<View style={{ height: 200, padding: 20, flexDirection: 'row' }}>
<YAxis
data={data}
style={{ marginBottom: xAxisHeight }}
contentInset={verticalContentInset}
svg={axesSvg}
/>
<View style={{ flex: 1, marginLeft: 10 }}>
<LineChart
style={{ flex: 1 }}
data={data}
contentInset={verticalContentInset}
svg={{ stroke: 'rgb(134, 65, 244)' }}
>
<Grid/>
</LineChart>
<XAxis
style={{ marginHorizontal: -10, height: xAxisHeight }}
data={data}
formatLabel={(value, index) => index}
contentInset={{ left: 10, right: 10 }}
svg={axesSvg}
/>
</View>
</View>
)
}
}
export default AxesExample