forked from JesperLekland/react-native-svg-charts-examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
area-chart.js
71 lines (63 loc) · 2.3 KB
/
area-chart.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
import React from 'react'
import { ClipPath, Defs, LinearGradient, Rect, Stop } from 'react-native-svg'
import { AreaChart, Path } from 'react-native-svg-charts'
class PartialAreaChartExample extends React.PureComponent {
render() {
const data = [ 50, 10, 40, 95, -4, -24, 85, 91, 35, 53, -53, 24, 50, -20, -80 ]
const indexToClipFrom = 10
const Gradient = () => (
<Defs key={ 'defs' }>
<LinearGradient id={ 'gradient' } x1={ '0%' } y={ '0%' } x2={ '0%' } y2={ '100%' }>
<Stop offset={ '0%' } stopColor={ 'rgb(134, 65, 244)' } stopOpacity={ 0.8 }/>
<Stop offset={ '100%' } stopColor={ 'rgb(134, 65, 244)' } stopOpacity={ 0.2 }/>
</LinearGradient>
</Defs>
)
const Clips = ({ x, width }) => (
<Defs key={ 'clips' }>
<ClipPath id={ 'clip-path-1' } key={ '0' }>
<Rect x={ 0 } y={ '0' } width={ x(indexToClipFrom) } height={ '100%' }/>
</ClipPath>
<ClipPath id="clip-path-2" key={ '1' }>
<Rect x={ x(indexToClipFrom) } y={ '0' } width={ width - x(indexToClipFrom) } height={ '100%' }/>
</ClipPath>
</Defs>
)
const Line = ({ line }) => (
<Path
key={ 'line' }
d={ line }
stroke={ 'green' }
fill={ 'none' }
clipPath={ 'url(#clip-path-1)' }
/>
)
const DashedLine = ({ line }) => (
<Path
key={ 'dashed-line' }
stroke={ 'green' }
d={ line }
fill={ 'none' }
clipPath={ 'url(#clip-path-2)' }
strokeDasharray={ [ 4, 4 ] }
/>
)
return (
<AreaChart
style={{ height: 200 }}
data={ data }
contentInset={{ top: 30, bottom: 30 }}
svg={{
fill: 'url(#gradient)',
clipPath: 'url(#clip-path-1)',
}}
>
<Gradient/>
<Clips/>
<Line/>
<DashedLine/>
</AreaChart>
)
}
}
export default PartialAreaChartExample