Features
- Adds a chart using just a single component.
- Auto-updates the chart object when the data source is modified.
- Adds a chart from a JSON URL, from a XML URL, or using Props Array Binding.
- Allows to include interactivity between javascript charts.
- Offers advanced control by giving you access to the complete FusionCharts object (that contains the chart configuration).
A Simple Chart
Quick Demo:
24
1
import Vue from 'vue';
2
import VueFusionCharts from 'vue-fusioncharts';
3
import FusionCharts from 'fusioncharts';
4
import Charts from 'fusioncharts/fusioncharts.charts';
5
6
//import the theme
7
import FusionTheme from 'fusioncharts/themes/fusioncharts.theme.fusion'
8
9
// register VueFusionCharts component
10
Vue.use(VueFusionCharts, FusionCharts, Charts, FusionTheme)
11
12
// Copy datasource from 'Data' tab
13
var dataSource = /*{ "chart": {..}, ..}*/;
14
15
var app = new Vue({
16
el: '#app',
17
data: {
18
width: '100%',
19
height: '400',
20
type: 'column2d',
21
dataFormat: 'json',
22
dataSource: dataSource
23
}
24
});
Quick Start
Step 1: Install the Vue-FusionCharts wrapper framework
In the terminal run the following command:
1
1
$ npm install vue-fusioncharts --save
Also install fusionCharts, if it is not already installed:
1
1
$ npm install fusioncharts --save
Step 2: Register the VueFusionCharts component
Use the Vue.use method to register the component globally:
In case of vue-cli or vue with bundlers, traditionally main.js contains the initialization code below
6
1
import Vue from 'vue';
2
import VueFusionCharts from 'vue-fusioncharts';
3
import FusionCharts from 'fusioncharts';
4
5
// register VueFusionCharts component
6
Vue.use(VueFusionCharts, FusionCharts);
Or, Use the Vue.component method to register the component locally:
6
1
import Vue from 'vue';
2
import FusionCharts from 'fusioncharts';
3
import { FCComponent } from 'vue-fusioncharts';
4
5
// register Vue-FusionCharts component
6
Vue.component('fusioncharts', FCComponent, FusionCharts);
Step 3: Render your Chart
For example render a simple pie chart
46
1
import Vue from 'vue';
2
import VueFusionCharts from 'vue-fusioncharts';
3
import FusionCharts from 'fusioncharts';
4
import Charts from 'fusioncharts/fusioncharts.charts'
5
6
// register VueFusionCharts component
7
Vue.use(VueFusionCharts, FusionCharts, Charts)
8
9
const myDataSource = {
10
"chart": {
11
"caption": "Recommended Portfolio Split",
12
"subCaption" : "For a net-worth of $1M",
13
"showValues":"1",
14
"showPercentInTooltip" : "0",
15
"numberPrefix" : "$",
16
"enableMultiSlicing":"1",
17
"theme": "fusion"
18
},
19
"data": [{
20
"label": "Equity",
21
"value": "300000"
22
}, {
23
"label": "Debt",
24
"value": "230000"
25
}, {
26
"label": "Bullion",
27
"value": "180000"
28
}, {
29
"label": "Real-estate",
30
"value": "270000"
31
}, {
32
"label": "Insurance",
33
"value": "20000"
34
}]
35
};
36
37
const chart = new Vue({
38
el: '#app',
39
data: {
40
type: 'pie2d',
41
width: '500',
42
height: '300',
43
dataFormat: 'json',
44
dataSource: myDataSource
45
}
46
});
Here's the HTML template for the above example
9
1
<div id="app">
2
<fusioncharts
3
:type="type"
4
:width="width"
5
:height="height"
6
:dataFormat="dataFormat"
7
:dataSource="dataSource">
8
</fusioncharts>
9
</div>
Usage and integration of FusionTime
From fusioncharts@3.13.3-sr.1 and vue-fusioncharts@3.0.0, You can visualize timeseries data easily with vue.
Consider the example below for integration of FusionTime
49
1
import Vue from 'vue';
2
import VueFusionCharts from 'vue-fusioncharts';
3
import FusionCharts from 'fusioncharts';
4
import TimeSeries from 'fusioncharts/fusioncharts.timeseries';
5
6
// register VueFusionCharts
7
Vue.use(VueFusionCharts, FusionCharts, TimeSeries);
8
9
const jsonify = res => res.json();
10
const dataFetch = fetch(
11
'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/master/assets/datasources/fusiontime/online-sales-single-series-area-data-plot/data.json'
12
).then(jsonify);
13
const schemaFetch = fetch(
14
'https://raw.githubusercontent.com/fusioncharts/dev_centre_docs/master/assets/datasources/fusiontime/online-sales-single-series-area-data-plot/schema.json'
15
).then(jsonify);
16
17
const chart = new Vue({
18
el: '#app',
19
data: {
20
width: '500',
21
height: '300',
22
type: 'timeseries',
23
dataFormat: 'json',
24
dataSource: {
25
caption: { text: 'Online Sales of a SuperStore in the US' },
26
data: null,
27
yAxis: [
28
{
29
plot: [
30
{
31
value: 'Sales ($)'
32
}
33
]
34
}
35
]
36
}
37
},
38
mounted: function() {
39
Promise.all([dataFetch, schemaFetch]).then(res => {
40
const data = res[0];
41
const schema = res[1];
42
const fusionTable = new FusionCharts.DataStore().createDataTable(
43
data,
44
schema
45
);
46
this.dataSource.data = fusionTable;
47
});
48
}
49
});
Here's the HTML template for the above example
11
1
<div id="app">
2
<fusioncharts
3
:width="width"
4
:height="height"
5
:type="type"
6
:dataFormat="dataFormat"
7
:dataSource="dataSource"
8
>
9
FusionCharts will render here
10
</fusioncharts>
11
</div>
© 2002-2018 InfoSoft Global Private Limited. All Rights Reserved.