-
Notifications
You must be signed in to change notification settings - Fork 1
/
F2Chart.js
88 lines (84 loc) · 2.15 KB
/
F2Chart.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
import React from 'react';
import {View, Text, ScrollView, Button, SafeAreaView} from 'react-native';
import Chart from 'react-native-f2chart';
import data from './data.json';
const initScript = (data) => `
(function(){
chart = new F2.Chart({
id: 'chart',
pixelRatio: window.devicePixelRatio,
});
chart.source(${JSON.stringify(data)}, {
value: {
tickCount: 5,
min: 0
},
date: {
type: 'timeCat',
range: [0, 1],
tickCount: 3
}
});
chart.tooltip({
custom: true,
showXTip: true,
showYTip: true,
snap: true,
onChange: function(obj) {
window.postMessage(stringify(obj))
},
crosshairsType: 'xy',
crosshairsStyle: {
lineDash: [2]
}
});
chart.axis('date', {
label: function label(text, index, total) {
var textCfg = {};
if (index === 0) {
textCfg.textAlign = 'left';
} else if (index === total - 1) {
textCfg.textAlign = 'right';
}
return textCfg;
}
});
chart.line().position('date*value');
chart.render();
})();
`;
const F2Chart = () => {
return (
<SafeAreaView>
<ScrollView>
<View>
<View>
<View style={{height: 350}}>
<Chart initScript={initScript(data)} />
</View>
</View>
<View>
<View
style={{
flexDirection: 'row',
height: 50,
alignItems: 'center',
justifyContent: 'space-between',
marginHorizontal: 20,
}}>
<Button title="10m" onPress={() => this.changeData(40)} />
<Button title="30m" onPress={() => this.changeData(30)} />
<Button title="1H" onPress={() => this.changeData(20)} />
<Button title="8H" onPress={() => this.changeData(10)} />
<Button title="1D" onPress={() => this.changeData(0)} />
</View>
<View style={{height: 350}}>
<Chart initScript={initScript(data)} />
</View>
</View>
</View>
</ScrollView>
</SafeAreaView>
);
};
export default F2Chart;