gpt4 book ai didi

javascript - 如何使用 JSON 在 Highcharts 同步图表中设置 yAxis 最小值/最大值

转载 作者:行者123 更新时间:2023-12-02 21:45:10 24 4
gpt4 key购买 nike

我正在使用 Highchart 的同步图表。很酷。但是,我想“规定” y 轴的最小值和最大值。我将这两个参数添加到 JSON 文件中,但不幸的是它们没有被接受。

JSON 文件:

    "unit": "km/h",
"type": "line",
"min": -2,
"max": 16,

y轴定义:

     yAxis: {
title: {
text: null
},
min: dataset.min,
max: dataset.max
},

但这不起作用。知道为什么吗? Here is the我正在使用的原始图形。 Here is a fiddle .

最佳答案

在 Highcharts API 中我们可以读到:

max: number, null

...

If the endOnTick option is true, the max value might be rounded up. (...)

作为解决方案,禁用 startOnTickendOnTick 选项或使用 tickPositioner 函数手动计算和设置刻度位置,例如:

            yAxis: {
...,
tickPositioner: function(){
var ticks = [],
step = (dataset.max - dataset.min) / 4;

for (var i = dataset.min; i <= dataset.max; i += step) {
ticks.push(i);
}

return ticks;
}
}

现场演示: https://jsfiddle.net/BlackLabel/ev5hz0pk/

API引用:

https://api.highcharts.com/highcharts/yAxis.max

https://api.highcharts.com/highcharts/yAxis.tickPositioner

关于javascript - 如何使用 JSON 在 Highcharts 同步图表中设置 yAxis 最小值/最大值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60269742/

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