|
1 | 1 | import React from 'react';
|
2 | 2 | import FusionCharts from 'fusioncharts';
|
3 | 3 | import Charts from 'fusioncharts/fusioncharts.charts';
|
4 |
| -import Column2d from 'fusioncharts/viz/column2d'; |
5 | 4 | import TimeSeries from 'fusioncharts/fusioncharts.timeseries';
|
6 | 5 | import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion';
|
7 | 6 | import ReactFC from '../lib/ReactFC';
|
8 | 7 |
|
9 |
| -// Charts(FusionCharts); |
10 |
| -// TimeSeries(FusionCharts); |
11 |
| -// OceanTheme(FusionCharts); |
12 | 8 | ReactFC.fcRoot(FusionCharts, Charts, TimeSeries, FusionTheme);
|
13 | 9 |
|
14 |
| -const myDataSource = { |
15 |
| - chart: { |
16 |
| - caption: "Harry's ss", |
17 |
| - subCaption: 'Top 5 stores in last month by revenue', |
18 |
| - numberPrefix: '$', |
19 |
| - theme: 'ocean' |
20 |
| - }, |
21 |
| - data: [ |
22 |
| - { |
23 |
| - label: 'Bakersfield Central', |
24 |
| - value: '880000' |
25 |
| - }, |
26 |
| - { |
27 |
| - label: 'Garden Groove harbour', |
28 |
| - value: '730000' |
29 |
| - }, |
30 |
| - { |
31 |
| - label: 'Los Angeles Topanga', |
32 |
| - value: '590000' |
33 |
| - }, |
34 |
| - { |
35 |
| - label: 'Compton-Rancho Dom', |
36 |
| - value: '520000' |
37 |
| - }, |
38 |
| - { |
39 |
| - label: 'Daly City Serramonte', |
40 |
| - value: '330000' |
41 |
| - } |
42 |
| - ] |
43 |
| -}; |
44 |
| - |
45 |
| -// const jsonify = res => res.json(); |
46 |
| -// const dataFetch = fetch( |
47 |
| -// 'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/data.json' |
48 |
| -// ).then(jsonify); |
49 |
| -// const schemaFetch = fetch( |
50 |
| -// 'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/fusiontime-beta-release/charts-resources/fusiontime/online-sales-single-series/schema.json' |
51 |
| -// ).then(jsonify); |
| 10 | +const BAR = 'bar2d'; |
52 | 11 |
|
53 | 12 | class ChartViewer extends React.Component {
|
54 | 13 | constructor(props) {
|
55 | 14 | super(props);
|
56 | 15 |
|
57 | 16 | this.state = {
|
58 |
| - timeseriesDs: { |
59 |
| - type: 'column2d', |
60 |
| - renderAt: 'container', |
61 |
| - width: '90%', |
62 |
| - height: 350, |
63 |
| - dataSource: { |
64 |
| - chart: { |
65 |
| - caption: "Harry's ss", |
66 |
| - subCaption: 'Top 5 stores in last month by revenue', |
67 |
| - numberPrefix: '$' |
68 |
| - }, |
69 |
| - data: [ |
70 |
| - { |
71 |
| - label: 'Bakersfield Central', |
72 |
| - value: '880000' |
73 |
| - }, |
74 |
| - { |
75 |
| - label: 'Garden Groove harbour', |
76 |
| - value: '730000' |
77 |
| - }, |
78 |
| - { |
79 |
| - label: 'Los Angeles Topanga', |
80 |
| - value: '590000' |
81 |
| - }, |
82 |
| - { |
83 |
| - label: 'Compton-Rancho Dom', |
84 |
| - value: '520000' |
85 |
| - }, |
86 |
| - { |
87 |
| - label: 'Daly City Serramonte', |
88 |
| - value: '330000' |
89 |
| - } |
90 |
| - ] |
91 |
| - } |
| 17 | + inverted: false, |
| 18 | + type: BAR, |
| 19 | + dataSource: { |
| 20 | + chart: { |
| 21 | + caption: 'Countries With Most Oil Reserves [2017-18]', |
| 22 | + subCaption: 'In MMbbl = One Million barrels', |
| 23 | + xAxisName: 'Country', |
| 24 | + yAxisName: 'Reserves (MMbbl)', |
| 25 | + numberSuffix: 'K', |
| 26 | + theme: 'fusion' |
| 27 | + }, |
| 28 | + data: [ |
| 29 | + { label: 'Venezuela', value: '290' }, |
| 30 | + { label: 'Saudi', value: '260' }, |
| 31 | + { label: 'Canada', value: '180' }, |
| 32 | + { label: 'Iran', value: '140' }, |
| 33 | + { label: 'Russia', value: '115' }, |
| 34 | + { label: 'UAE', value: '100' }, |
| 35 | + { label: 'US', value: '30' }, |
| 36 | + { label: 'China', value: '300' } |
| 37 | + ] |
92 | 38 | }
|
93 | 39 | };
|
94 |
| - |
95 |
| - this.onChangeSize = this.onChangeSize.bind(this); |
96 |
| - this.onFetchData = this.onFetchData.bind(this); |
97 |
| - this.onChangeCaption = this.onChangeCaption.bind(this); |
| 40 | + this.onChange = this.onChange.bind(this); |
98 | 41 | }
|
99 | 42 |
|
100 |
| - componentDidMount() { |
101 |
| - // this.onFetchData(); |
102 |
| - } |
103 |
| - |
104 |
| - onChangeSize() { |
105 |
| - const timeseriesDs = { ...this.state.timeseriesDs }; |
106 |
| - timeseriesDs.height = 600; |
107 |
| - timeseriesDs.width = 600; |
108 |
| - this.setState({ timeseriesDs }, () => { |
109 |
| - console.log(this.state.timeseriesDs); |
110 |
| - }); |
111 |
| - } |
112 |
| - |
113 |
| - onFetchData() { |
114 |
| - // Promise.all([dataFetch, schemaFetch]).then(res => { |
115 |
| - // const data = res[0]; |
116 |
| - // const schema = res[1]; |
117 |
| - // const fusionTable = new FusionCharts.DataStore().createDataTable( |
118 |
| - // data, |
119 |
| - // schema |
120 |
| - // ); |
121 |
| - // const timeseriesDs = Object.assign({}, this.state.timeseriesDs); |
122 |
| - // timeseriesDs.dataSource.data = fusionTable; |
123 |
| - // this.setState({ |
124 |
| - // timeseriesDs |
125 |
| - // }); |
126 |
| - // }); |
127 |
| - } |
128 |
| - |
129 |
| - onChangeCaption() { |
130 |
| - // console.log(this.state.timeseriesDs); |
131 |
| - const timeseriesDs = { ...this.state.timeseriesDs }; |
132 |
| - timeseriesDs.dataSource.caption.text = 'Random'; |
133 |
| - this.setState( |
134 |
| - { |
135 |
| - timeseriesDs |
136 |
| - }, |
137 |
| - () => { |
138 |
| - // this.onChangeSize(); |
| 43 | + onChange() { |
| 44 | + this.setState(({ dataSource }) => ({ |
| 45 | + dataSource: { |
| 46 | + ...dataSource, |
| 47 | + chart: { ...dataSource.chart, caption: 'CHANGED IT!!!!!!!' } |
139 | 48 | }
|
140 |
| - ); |
| 49 | + })); |
141 | 50 | }
|
142 | 51 |
|
143 | 52 | render() {
|
144 | 53 | return (
|
145 | 54 | <div>
|
146 |
| - {/* <ReactFC {...this.state} /> */} |
147 |
| - {this.state.timeseriesDs.dataSource.data ? ( |
148 |
| - <ReactFC |
149 |
| - type="line" |
150 |
| - width="600" |
151 |
| - height="400" |
152 |
| - dataSource={{ |
153 |
| - chart: { |
154 |
| - theme: 'fusion', |
155 |
| - caption: 'Total footfall in Bakersfield Central', |
156 |
| - subCaption: 'Last week', |
157 |
| - xAxisName: 'Day', |
158 |
| - yAxisName: 'No. of Visitors', |
159 |
| - lineThickness: '2', |
160 |
| - showXAxisLine: 1, |
161 |
| - showYAxisLine: 1, |
162 |
| - numDivLines: 7, |
163 |
| - numVDivLines: 7, |
164 |
| - showToolTip: 1 |
165 |
| - }, |
166 |
| - data: [ |
167 |
| - { |
168 |
| - label: 'Mon', |
169 |
| - value: '15123' |
170 |
| - }, |
171 |
| - { |
172 |
| - label: 'Tue', |
173 |
| - value: '14233' |
174 |
| - }, |
175 |
| - { |
176 |
| - label: 'Wed', |
177 |
| - value: '23507' |
178 |
| - }, |
179 |
| - { |
180 |
| - label: 'Thu', |
181 |
| - value: '9110' |
182 |
| - }, |
183 |
| - { |
184 |
| - label: 'Fri', |
185 |
| - value: '15529' |
186 |
| - }, |
187 |
| - { |
188 |
| - label: 'Sat', |
189 |
| - value: '20803' |
190 |
| - }, |
191 |
| - { |
192 |
| - label: 'Sun', |
193 |
| - value: '19202' |
194 |
| - } |
195 |
| - ] |
196 |
| - }} |
197 |
| - /> |
198 |
| - ) : ( |
199 |
| - 'loading' |
200 |
| - )} |
201 |
| - <div> |
202 |
| - <button onClick={this.onChangeSize}>Change Size</button> |
203 |
| - <button onClick={this.onChangeCaption}>Change Caption</button> |
204 |
| - </div> |
| 55 | + <ReactFC |
| 56 | + type={this.state.type} |
| 57 | + width={this.state.inverted ? '400' : '600'} |
| 58 | + height={this.state.inverted ? '600' : '400'} |
| 59 | + dataFormat="json" |
| 60 | + dataSource={this.state.dataSource} |
| 61 | + /> |
| 62 | + <button onClick={this.onChange}>CHANGE</button> |
205 | 63 | </div>
|
206 | 64 | );
|
207 | 65 | }
|
|
0 commit comments