是否可以使用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
}
仅限鼠标滚轮(默认为) 感谢
答案 0 :(得分:0)
您可以使用事件处理程序来检查/更新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();
});