-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
122 lines (110 loc) · 3.02 KB
/
App.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
import React from 'react';
import {StyleSheet, View, processColor} from 'react-native';
import {LineChart} from 'react-native-charts-wrapper';
import update from 'immutability-helper';
export default class App extends React.Component {
constructor(props) {
super(props);
this.values = [{x: 0, y: 3}, {x: 1, y: 6}, {x: 2, y: 9}, {x: 3, y: 12}];
this.values2 = [{x: 0, y: 3}, {x: 1, y: 6}, {x: 2, y: 9}, {x: 3, y: 12}];
this.values3 = [{x: 0, y: 3}, {x: 1, y: 6}, {x: 2, y: 9}, {x: 3, y: 12}];
}
componentDidMount() {
setInterval(() => {
let newVal = this.filter(this.values[this.values.length - 1].y);
let newX = this.values.length;
let vals = update(this.values, {
$push: [{x: newX, y: newVal}, {x: newX + 1, y: newVal + 5}],
});
let vals2 = update(this.values2, {
$push: [{x: newX, y: newVal * 2}, {x: newX + 1, y: (newVal + 5) * 2}],
});
let vals3 = update(this.values3, {
$push: [
{x: newX, y: newVal + newVal * 2},
{x: newX + 1, y: newVal + 5 + (newVal + 5) * 2},
],
});
if (!this.chartRef) {
return;
}
this.chartRef.addEntries([
{
index: 0,
values: [{x: newX, y: newVal}, {x: newX + 1, y: newVal + 5}],
},
{
index: 1,
values: [
{x: newX, y: newVal * 2},
{x: newX + 1, y: (newVal + 5) * 2},
],
},
{
index: 2,
values: [
{x: newX, y: newVal + newVal * 2},
{x: newX + 1, y: newVal + 5 + (newVal + 5) * 2},
],
},
]);
this.values = vals;
this.values2 = vals2;
this.values3 = vals3;
}, 20);
}
filter(val) {
return Math.cos(val) * 10;
}
render() {
return (
<View style={styles.container}>
<LineChart
ref={ref => (this.chartRef = ref)}
style={styles.chart}
xAxis={{granularityEnabled: true, granularity: 1}}
data={{
dataSets: [
{
label: 'demo',
values: this.values,
config: {
drawCircles: false,
drawValues: false,
colors: [processColor('red')],
},
},
{
label: 'demo2',
values: this.values2,
config: {
drawCircles: false,
drawValues: false,
colors: [processColor('green')],
},
},
{
label: 'demo3',
values: this.values3,
config: {
drawCircles: false,
drawValues: false,
colors: [processColor('black')],
},
},
],
}}
/>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#F5FCFF',
},
chart: {
flex: 1,
},
});