-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMultipchart.js
209 lines (204 loc) · 6 KB
/
Multipchart.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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import React, {useEffect, useState, useRef} from 'react';
import {
View,
Text,
SafeAreaView,
StyleSheet,
Dimensions,
TouchableOpacity,
} from 'react-native';
import axios from 'axios';
import {
VictoryBar,
VictoryAxis,
VictoryCandlestick,
VictoryChart,
VictoryTheme,
VictoryArea,
VictoryLine,
} from 'victory-native';
import Menu, {MenuItem, MenuDivider} from 'react-native-material-menu';
import Icons from 'react-native-vector-icons/MaterialIcons';
import IonIcon from 'react-native-vector-icons/Ionicons';
const Multipchart = () => {
const [state, setState] = useState({data: [], chartType: 'candlestick'});
const setMenuRef = useRef(null);
const chartMenuRef = useRef(null);
useEffect(() => {
const apiSetup = axios.create({
baseURL:
'https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=50',
timeout: 10000,
});
const response = apiSetup
.get('')
.then((res) => setState({...state, data: res.data.Data.Data}))
.catch((error) => console.log(error));
}, []);
console.log('State ', state.data);
const values = () => {
const ar =
state &&
state.data.map((item) => {
return {x: item.time, y: item.close};
});
return ar;
};
const showMenu = () => {
setMenuRef.current.show();
};
const hindeMenu = () => {
setMenuRef.current.hide();
};
const changeChart = (chartName) => {
setState({...state, chartType: chartName});
chartMenuRef.current.hide();
};
const showChartMenu = () => {
chartMenuRef.current.show();
};
const graphType = () => {
if (state.chartType === 'candlestick') {
return (
<View style={styles.container}>
<VictoryChart scale={{x: 'time'}}>
<VictoryAxis tickFormat={(t) => `${t.getDate()}/${t.getMonth()}`} />
<VictoryAxis dependentAxis />
<VictoryCandlestick
candleColors={{positive: '#5f5c5b', negative: '#c43a31'}}
data={state.data.length > 0 ? state.data : null}
/>
</VictoryChart>
</View>
);
} else {
return (
<View style={styles.container}>
<VictoryChart scale={{x: 'time'}}>
<VictoryAxis
tickValues={state.data.map(
(item) =>
new Date(item.time).getFullYear() +
'/' +
new Date(item.time).getDate(),
)}
tickCount={5}
//scale={{ x: "time" }}
/>
<VictoryAxis
dependentAxis
tickValues={state && state.data.map((item) => item.close)}
tickCount={5}
orientation="right"
//scale={{ y: "time" }}
/>
<VictoryLine
style={{
data: {stroke: '#c43a31'},
parent: {border: '1px solid #ccc'},
}}
data={state.data.length > 0 ? values() : null}
/>
</VictoryChart>
</View>
);
}
};
return (
<SafeAreaView style={{flex: 1}}>
<View style={styles.container}>
<View
style={{
width: '100%',
flexDirection: 'row',
alignItems: 'center',
backgroundColor: 'black',
justifyContent: 'space-between',
height: 50,
}}>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
}}>
<Menu
ref={setMenuRef}
button={
<TouchableOpacity
onPress={showMenu}
style={{
marginHorizontal: 20,
flexDirection: 'row',
alignItems: 'center',
}}>
<Text onPress={showMenu} style={{color: 'white'}}>
1 Day
</Text>
<Icons name="arrow-drop-down" size={25} color="white" />
</TouchableOpacity>
}>
<MenuItem onPress={hindeMenu}>1 Day</MenuItem>
<MenuItem onPress={hindeMenu}>2 Day</MenuItem>
</Menu>
<Menu
ref={chartMenuRef}
button={
<TouchableOpacity
onPress={showChartMenu}
style={{
marginHorizontal: 20,
flexDirection: 'row',
alignItems: 'center',
}}>
<Text onPress={showChartMenu} style={{color: 'white'}}>
💹
</Text>
<Icons name="arrow-drop-down" size={25} color="white" />
</TouchableOpacity>
}>
<MenuItem onPress={changeChart.bind(this, 'candlestick')}>
CandleStick
</MenuItem>
<MenuItem onPress={changeChart.bind(this, 'LineChart')}>
Line
</MenuItem>
</Menu>
</View>
<View
style={{
flexDirection: 'row',
alignItems: 'center',
}}>
<TouchableOpacity
onPress={null}
style={{
marginHorizontal: 20,
flexDirection: 'row',
alignItems: 'center',
}}>
<Icons name="settings" size={25} color="white" />
</TouchableOpacity>
<TouchableOpacity
onPress={null}
style={{
marginHorizontal: 20,
flexDirection: 'row',
alignItems: 'center',
}}>
<IonIcon name="ios-expand" size={25} color="white" />
</TouchableOpacity>
</View>
</View>
{graphType()}
</View>
</SafeAreaView>
);
};
export default Multipchart;
const styles = StyleSheet.create({
container: {
justifyContent: 'center',
alignItems: 'center',
backgroundColor: '#f5fcff',
},
});