是否可以使用chartjs实现用于快速缩放的缩放按钮(+和-按钮)
现在我使用这个代码:
pan: {
enabled: true,
mode: 'xy',
rangeMin: {
// Format of min pan range depends on scale type
x: null,
y: null
},
rangeMax: {
// Format of max pan range depends on scale type
x: null,
y: null
}
},
zoom: {
enabled: true,
mode: 'xy',
rangeMin: {
// Format of min pan range depends on scale type
x: 1,
y: 1
},
rangeMax: {
// Format of max pan range depends on scale type
x: 5,
y: 5
}
仅通过鼠标滚轮(默认)
谢谢
最佳答案
您可以使用事件处理程序来检查/更新 xAxes 的刻度,以实现类似的效果:
$('#zoom_in').click(function(){
ticks = myChart.chart.options.scales.xAxes[0].ticks;
/* if x-axis is categorical, use the data.labels to determine current axis range, e.g.:
labels = myChart.chart.data.labels;
startTick = labels.indexOf(ticks.min);
endTick = labels.indexOf(ticks.max);
*/
// below assumes ticks.min and ticks.max are numeric
var diff = ticks.max - ticks.min;
var factor = 0.05;
var newMin = ticks.min + factor * diff;
var newMax = ticks.max - factor * diff;
ticks.min = newMin;
ticks.max = newMax;
myChart.update();
});
关于chart.js - 用按钮实现chartjs缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49727597/