11import React from 'react' ;
22import FusionCharts from 'fusioncharts' ;
33import Charts from 'fusioncharts/fusioncharts.charts' ;
4+ import TimeSeries from 'fusioncharts/fusioncharts.timeseries' ;
45import OceanTheme from 'fusioncharts/themes/fusioncharts.theme.ocean' ;
56import ReactFC from '../lib/ReactFC' ;
67
78Charts ( FusionCharts ) ;
9+ TimeSeries ( FusionCharts ) ;
810OceanTheme ( FusionCharts ) ;
911
1012const myDataSource = {
1113 chart : {
12- caption : ' Harry\ 's ss' ,
14+ caption : " Harry's ss" ,
1315 subCaption : 'Top 5 stores in last month by revenue' ,
1416 numberPrefix : '$' ,
15- theme : 'ocean' ,
17+ theme : 'ocean'
1618 } ,
1719 data : [
1820 {
1921 label : 'Bakersfield Central' ,
20- value : '880000' ,
22+ value : '880000'
2123 } ,
2224 {
2325 label : 'Garden Groove harbour' ,
24- value : '730000' ,
26+ value : '730000'
2527 } ,
2628 {
2729 label : 'Los Angeles Topanga' ,
28- value : '590000' ,
30+ value : '590000'
2931 } ,
3032 {
3133 label : 'Compton-Rancho Dom' ,
32- value : '520000' ,
34+ value : '520000'
3335 } ,
3436 {
3537 label : 'Daly City Serramonte' ,
36- value : '330000' ,
37- } ,
38- ] ,
38+ value : '330000'
39+ }
40+ ]
3941} ;
4042
43+ const jsonify = res => res . json ( ) ;
44+ const dataFetch = fetch (
45+ 'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/data.json'
46+ ) . then ( jsonify ) ;
47+ const schemaFetch = fetch (
48+ 'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/schema.json'
49+ ) . then ( jsonify ) ;
50+
4151class ChartViewer extends React . Component {
4252 constructor ( props ) {
4353 super ( props ) ;
@@ -48,9 +58,35 @@ class ChartViewer extends React.Component {
4858 height : 400 ,
4959 dataFormat : 'json' ,
5060 dataSource : myDataSource ,
61+ timeseriesDs : {
62+ type : 'timeseries' ,
63+ renderAt : 'container' ,
64+ width : '90%' ,
65+ height : 350 ,
66+ dataSource : {
67+ data : null ,
68+ yAxis : [
69+ {
70+ plot : [
71+ {
72+ value : 'Sales ($)'
73+ }
74+ ]
75+ }
76+ ] ,
77+ caption : {
78+ text : 'Online Sales of a SuperStore in the US'
79+ }
80+ }
81+ }
5182 } ;
5283
5384 this . onClick = this . onClick . bind ( this ) ;
85+ this . onFetchData = this . onFetchData . bind ( this ) ;
86+ }
87+
88+ componentDidMount ( ) {
89+ this . onFetchData ( ) ;
5490 }
5591
5692 onClick ( ) {
@@ -67,20 +103,54 @@ class ChartViewer extends React.Component {
67103 <set label="Golf" value="400000000" tooltext="Popular in: {br}US{br}Canada{br}Europe" />
68104 <set label="Basketball" value="400000000" tooltext="Popular in: {br}US{br}Canada" />
69105 <set label="American football" value="390000000" tooltext="Popular in:{br}US" />
70- </chart>` ,
106+ </chart>`
107+ } ) ;
108+ }
109+
110+ onFetchData ( ) {
111+ Promise . all ( [ dataFetch , schemaFetch ] ) . then ( res => {
112+ const data = res [ 0 ] ;
113+ const schema = res [ 1 ] ;
114+
115+ // console.log(data);
116+ // console.log(schema);
117+ const fusionTable = new FusionCharts . DataStore ( ) . createDataTable (
118+ data ,
119+ schema
120+ ) ;
121+
122+ this . setState (
123+ {
124+ timeseriesDs : {
125+ ...this . state . timeseriesDs ,
126+ dataSource : {
127+ ...this . state . timeseriesDs . dataSource ,
128+ data : fusionTable
129+ }
130+ }
131+ } ,
132+ ( ) => {
133+ // console.log(this.state.timeseriesDs);
134+ }
135+ ) ;
71136 } ) ;
72137 }
73138
74139 render ( ) {
75140 return (
76141 < div >
77- < ReactFC { ...this . state } />
142+ { /* <ReactFC {...this.state} /> */ }
143+ { this . state . timeseriesDs . dataSource . data ? (
144+ < ReactFC { ...this . state . timeseriesDs } />
145+ ) : (
146+ 'loading'
147+ ) }
78148 < div >
79- < button onClick = { this . onClick } > Click</ button >
149+ < button onClick = { this . onFetchData } > Click</ button >
80150 </ div >
81151 </ div >
82152 ) ;
83153 }
84154}
85155
86- export default ChartViewer ;
156+ export default ChartViewer ;
0 commit comments