dscogs
dscogs

Reputation: 41

Chart JS Zoom Pan

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

Answers (2)

Alif Lam Mim
Alif Lam Mim

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

bloox
bloox

Reputation: 127

Yes, you can change this by setting "enabled" to false and/or use chart.resetZoom() link

Upvotes: 1

Related Questions