Listen to events from chart
Bind event listener to the chart and get the related event data
by Ashok Mandal
HTML
<script src="https://unpkg.com/[email protected]/dist/vue-fusioncharts.js"></script>
<script src="https://cdn.fusioncharts.com/fusioncharts/latest/fusioncharts.js"></script>
<script src="https://cdn.fusioncharts.com/fusioncharts/latest/themes/fusioncharts.theme.fusion.js"></script>
<div id="app">
<fusioncharts
:type="type"
:width="width"
:height="height"
:dataFormat="dataFormat"
:dataSource="dataSource"
@dataplotRollover="dataplotRollover"
></fusioncharts>
<div class="text-style" v-html="displayValue"></div>
</div>
CSS
.text-style {
padding: 10px;
background: #f5f2f0;
text-align: center;
}
Vue
// register VueFusionCharts plugin
Vue.use(VueFusionCharts, FusionCharts)
var dataSource = {
"chart": {
"caption": "Countries With Most Oil Reserves [2017-18]",
"subCaption": "In MMbbl = One Million barrels",
"xAxisName": "Country",
"yAxisName": "Reserves (MMbbl)",
"numberSuffix": "K",
"theme": "fusion"
},
"data": [{
"label": "Venezuela",
"value": "290"
}, {
"label": "Saudi",
"value": "260"
}, {
"label": "Canada",
"value": "180"
}, {
"label": "Iran",
"value": "140"
}, {
"label": "Russia",
"value": "115"
}, {
"label": "UAE",
"value": "100"
}, {
"label": "US",
"value": "30"
}, {
"label": "China",
"value": "30"
}]
};
var app = new Vue({
el: '#app',
data: {
width: '100%',
height: '400',
type: 'column2d',
dataFormat: 'json',
dataSource: dataSource,
displayValue:'Hover on the plot to see the value along with the label'
},
methods: {
// uses the data info of the event 'dataplotrollover' and represents it
dataplotRollover: function (e) {
this.displayValue = `You are currently hovering over <strong>${e.data.categoryLabel}</strong> whose value is <strong>${e.data.displayValue}</strong>`;
}
}
});