gpt4 book ai didi

chart.js - 用按钮实现chartjs缩放

转载 作者:行者123 更新时间:2023-12-03 14:57:15 25 4
gpt4 key购买 nike

是否可以使用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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com