forked from JesperLekland/react-native-svg-charts-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscale-time.js
76 lines (70 loc) · 2.37 KB
/
scale-time.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
75
76
import React from 'react'
import { AreaChart, XAxis, Grid } from 'react-native-svg-charts'
import { View } from 'react-native'
import * as scale from 'd3-scale'
import * as shape from 'd3-shape'
import dateFns from 'date-fns'
class XAxisScaleTimeExample extends React.PureComponent {
render() {
const data = [
{
value: 50,
date: dateFns.setHours(new Date(2018, 0, 0), 6),
},
{
value: 10,
date: dateFns.setHours(new Date(2018, 0, 0), 9),
},
{
value: 150,
date: dateFns.setHours(new Date(2018, 0, 0), 15),
},
{
value: 10,
date: dateFns.setHours(new Date(2018, 0, 0), 18),
},
{
value: 100,
date: dateFns.setHours(new Date(2018, 0, 0), 21),
},
{
value: 20,
date: dateFns.setHours(new Date(2018, 0, 0), 24),
},
]
return (
<View style={{ height: 200, padding: 20 }}>
<AreaChart
style={{ flex: 1 }}
data={ data }
yAccessor={ ({ item }) => item.value }
xAccessor={ ({ item }) => item.date }
xScale={ scale.scaleTime }
contentInset={{ top: 10, bottom: 10 }}
svg={{ fill: 'rgba(134, 65, 244, 0.5)' }}
curve={ shape.curveLinear }
>
<Grid/>
</AreaChart>
<XAxis
data={ data }
svg={{
fill: 'black',
fontSize: 8,
fontWeight: 'bold',
rotation: 20,
originY: 30,
y: 5,
}}
xAccessor={ ({ item }) => item.date }
scale={ scale.scaleTime }
numberOfTicks={ 6 }
style={{ marginHorizontal: -15, height: 20 }}
contentInset={{ left: 10, right: 25 }}
formatLabel={ (value) => dateFns.format(value, 'HH:mm') }
/>
</View>
)
}
}
export default XAxisScaleTimeExample