Skip to content

Commit 7be7b22

Browse files
committed
Added README for TimeSeries
1 parent a95e12a commit 7be7b22

File tree

2 files changed

+106
-24
lines changed

2 files changed

+106
-24
lines changed

README.md

Lines changed: 88 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A simple and lightweight official React component for FusionCharts JavaScript ch
2424
- [Custom Components](#custom-components)
2525
- [Drill Down](#drill-down-component)
2626
- [Going Beyond Charts](#going-beyond-charts)
27+
- [Usage and Integration of FusionTime](#usage-and-integration-of-fusionTime)
2728
- [For Contributors](#for-contributors)
2829
- [Licensing](#licensing)
2930

@@ -76,7 +77,7 @@ ReactFC.fcRoot(FusionCharts);
7677

7778
Here is a basic sample that shows how to create a chart using `react-fusioncharts`:
7879

79-
```
80+
```javascript
8081
import React from 'react;
8182
import ReactDOM from 'react-dom';
8283
import FusionCharts from 'fusioncharts';
@@ -263,6 +264,92 @@ class Chart extends Component {
263264
ReactDOM.render(<Chart />, document.getElementById('root'));
264265
```
265266
267+
## Usage and integration of FusionTime
268+
269+
From `fusioncharts@3.13.3-sr.1` and `react-fusioncharts@3.0.0`, You can visualize timeseries data easily on react.
270+
271+
Learn more about FusionTime [here](https://www.fusioncharts.com/fusiontime).
272+
273+
### Consider the example below for integration of FusionTime
274+
275+
```javascript
276+
import React from 'react';
277+
import FusionCharts from 'fusioncharts';
278+
import TimeSeries from 'fusioncharts/fusioncharts.timeseries';
279+
import ReactFC from '../lib/ReactFC';
280+
281+
ReactFC.fcRoot(FusionCharts, TimeSeries);
282+
283+
const jsonify = res => res.json();
284+
const dataFetch = fetch(
285+
'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/data.json'
286+
).then(jsonify);
287+
const schemaFetch = fetch(
288+
'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/schema.json'
289+
).then(jsonify);
290+
291+
class ChartViewer extends React.Component {
292+
constructor(props) {
293+
super(props);
294+
295+
this.state = {
296+
timeseriesDs: {
297+
type: 'timeseries',
298+
renderAt: 'container',
299+
width: '600',
300+
height: '400',
301+
dataSource: {
302+
caption: { text: 'Online Sales of a SuperStore in the US' },
303+
data: null,
304+
yAxis: [
305+
{
306+
plot: [
307+
{
308+
value: 'Sales ($)'
309+
}
310+
]
311+
}
312+
]
313+
}
314+
}
315+
};
316+
this.onFetchData = this.onFetchData.bind(this);
317+
}
318+
319+
componentDidMount() {
320+
this.onFetchData();
321+
}
322+
323+
onFetchData() {
324+
Promise.all([dataFetch, schemaFetch]).then(res => {
325+
const data = res[0];
326+
const schema = res[1];
327+
const fusionTable = new FusionCharts.DataStore().createDataTable(
328+
data,
329+
schema
330+
);
331+
const timeseriesDs = Object.assign({}, this.state.timeseriesDs);
332+
timeseriesDs.dataSource.data = fusionTable;
333+
this.setState({
334+
timeseriesDs
335+
});
336+
});
337+
}
338+
339+
render() {
340+
return (
341+
<div>
342+
{this.state.timeseriesDs.dataSource.data ? (
343+
<ReactFC {...this.state.timeseriesDs} />
344+
) : (
345+
'loading'
346+
)}
347+
</div>
348+
);
349+
}
350+
}
351+
```
352+
266353
## Drill Down Component
267354

268355
A custom component to easily add drill down to your react application.

example/ChartViewer.js

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ import TimeSeries from 'fusioncharts/fusioncharts.timeseries';
55
import OceanTheme from 'fusioncharts/themes/fusioncharts.theme.ocean';
66
import ReactFC from '../lib/ReactFC';
77

8-
Charts(FusionCharts);
9-
TimeSeries(FusionCharts);
10-
OceanTheme(FusionCharts);
8+
// Charts(FusionCharts);
9+
// TimeSeries(FusionCharts);
10+
// OceanTheme(FusionCharts);
11+
ReactFC.fcRoot(FusionCharts, Charts, TimeSeries);
1112

1213
const myDataSource = {
1314
chart: {
@@ -77,6 +78,7 @@ class ChartViewer extends React.Component {
7778
this.onChangeSize = this.onChangeSize.bind(this);
7879
this.onFetchData = this.onFetchData.bind(this);
7980
this.onChangeCaption = this.onChangeCaption.bind(this);
81+
this.onChange = this.onChange.bind(this);
8082
}
8183

8284
componentDidMount() {
@@ -88,36 +90,23 @@ class ChartViewer extends React.Component {
8890
timeseriesDs.height = 600;
8991
timeseriesDs.width = 600;
9092
this.setState({ timeseriesDs }, () => {
91-
// console.log(this.state.timeseriesDs);
93+
console.log(this.state.timeseriesDs);
9294
});
9395
}
9496

9597
onFetchData() {
9698
Promise.all([dataFetch, schemaFetch]).then(res => {
9799
const data = res[0];
98100
const schema = res[1];
99-
100-
// console.log(data);
101-
// console.log(schema);
102101
const fusionTable = new FusionCharts.DataStore().createDataTable(
103102
data,
104103
schema
105104
);
106-
107-
this.setState(
108-
{
109-
timeseriesDs: {
110-
...this.state.timeseriesDs,
111-
dataSource: {
112-
...this.state.timeseriesDs.dataSource,
113-
data: fusionTable
114-
}
115-
}
116-
},
117-
() => {
118-
// console.log(this.state.timeseriesDs);
119-
}
120-
);
105+
const timeseriesDs = Object.assign({}, this.state.timeseriesDs);
106+
timeseriesDs.dataSource.data = fusionTable;
107+
this.setState({
108+
timeseriesDs
109+
});
121110
});
122111
}
123112

@@ -130,11 +119,16 @@ class ChartViewer extends React.Component {
130119
timeseriesDs
131120
},
132121
() => {
133-
// console.log(this.state.timeseriesDs);
122+
// this.onChangeSize();
134123
}
135124
);
136125
}
137126

127+
onChange() {
128+
this.onChangeCaption();
129+
this.onChangeSize();
130+
}
131+
138132
render() {
139133
return (
140134
<div>
@@ -147,6 +141,7 @@ class ChartViewer extends React.Component {
147141
<div>
148142
<button onClick={this.onChangeSize}>Change Size</button>
149143
<button onClick={this.onChangeCaption}>Change Caption</button>
144+
<button onClick={this.onChange}>Change Both</button>
150145
</div>
151146
</div>
152147
);

0 commit comments

Comments
 (0)