可视化点击x轴标签实现标签文字切换
function getIndex(x, first, last, diff) {
if (x < first) {
return 0;
}
if (x > last) {
return Math.floor((last - first) / diff);
}
return Math.floor((x - first) / diff);
}
y轴可以自己定义一范围
// 测试示例
console.log(getIndex(5, 10, 100, 10)); // 输出: 0
console.log(getIndex(20, 10, 100, 10)); // 输出: 1
console.log(getIndex(30, 10, 100, 10)); // 输出: 2
console.log(getIndex(35, 10, 100, 10)); // 输出: 2
console.log(getIndex(105, 10, 100, 10)); // 输出: 9
本文来自博客园,作者:jialiangzai,转载请注明原文链接:https://www.cnblogs.com/zsnhweb/p/18706160

浙公网安备 33010602011771号