Reputation: 41
I am using the Chart JS Zoom/Pan Plugin (https://github.com/chartjs/chartjs-plugin-zoom) and was wondering if there is a way to disable it when there is no data present. The current basic options settings are
pan: {
enabled: true,
mode: 'x'
},
zoom: {
enabled: true,
mode: 'x'
}
Upvotes: 1
Views: 10786
Reputation: 1
Try this:
// since myChart.update() is not working. You need to do this.
var myChartOptions = myChart.options; // need to store in variable.
// check data present
if (data.length > 0) {
myChartOptions.pan.enabled = true;
myChartOptions.zoom.enabled = true;
myChart.options = myChartOptions; // update myChart.options.
}
else {
myChartOptions.pan.enabled = false;
myChartOptions.zoom.enabled = false;
myChart.options = myChartOptions; // update myChart.options.
}
Upvotes: 0