Chart JS Zoom Pan

时间:2017-07-25 17:41:20

标签: chart.js chart.js2

我正在使用Chart JS Zoom / Pan插件(https://github.com/chartjs/chartjs-plugin-zoom)并想知道是否有办法在没有数据时禁用它。当前的基本选项设置是

{{1}}

2 个答案:

答案 0 :(得分:1)

是的,您可以通过设置"启用"来更改此设置为false和/或使用chart.resetZoom()link

答案 1 :(得分:0)

尝试一下:

// 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.
}