-
Notifications
You must be signed in to change notification settings - Fork 1
/
FusionCharts.js
100 lines (95 loc) · 2.68 KB
/
FusionCharts.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
import React, { Component } from 'react';
import { Platform, StyleSheet, Text, View, Button, Alert } from 'react-native';
import FusionCharts from 'react-native-fusioncharts';
const jsonify = res => res.json();
// This is the remote url to fetch the data.
const dataFetch = fetch(
'https://s3.eu-central-1.amazonaws.com/fusion.store/ft/data/area-chart-with-time-axis-data.json'
).then(jsonify);
// This is the remote url to fetch the schema.
const schemaFetch = fetch(
'https://s3.eu-central-1.amazonaws.com/fusion.store/ft/schema/area-chart-with-time-axis-schema.json'
).then(jsonify);
export default class AreaTimeAxis extends Component {
constructor(props) {
super(props);
this.apiCaller = null;
this.state = {
type: 'timeseries',
width: '100%',
height: '100%',
dataFormat: 'json',
chartType: '',
dataSource: {
chart: {
showLegend: 0
},
caption: {
text: 'Daily Visitors Count of a Website'
},
yAxis: [
{
plot: {
value: 'Daily Visitors',
type: 'area'
},
title: 'Daily Visitors (in thousand)'
}
],
// Initially data is set as null
data: null
},
schemaJson: null,
dataJson: null
};
this.libraryPath = Platform.select({
// Specify fusioncharts.html file location
android: { uri: 'file:///android_asset/fusioncharts.html' },
ios: require('./assets/fusioncharts.html')
});
}
// We are creating the DataTable immidietly after the component is mounted
componentDidMount() {
Promise.all([dataFetch, schemaFetch]).then(res => {
const data = res[0];
const schema = res[1];
this.setState({ dataJson: data, schemaJson: schema });
});
}
render() {
return (
<View style={styles.container}>
<Text style={styles.header}>Area Chart with Time Axis</Text>
<View style={styles.chartContainer}>
<FusionCharts
dataJson={this.state.dataJson}
schemaJson={this.state.schemaJson}
type={this.state.type}
width={this.state.width}
height={this.state.height}
dataFormat={this.state.dataFormat}
dataSource={this.state.dataSource}
libraryPath={this.libraryPath} // set the libraryPath property
/>
</View>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
padding: 10
},
header: {
fontWeight: 'bold',
fontSize: 20,
textAlign: 'center',
paddingBottom: 10
},
chartContainer: {
height: 400,
borderColor: '#000',
borderWidth: 1
}
});