我在 highchart 上使用区域样条图表类型。我在此图表中使用的系列定义如下:
var data = [{ datetime: '08:35', value: '2087696.02'},
{datetime: '08:40', value: '2087696.02'},
{ datetime: '08:45', value: '2087696.02'},
{datetime: '08:50', value: '2087696.02'},
{datetime: '08:55', value: '2087696.02},
{datetime: '09:00', value: '2087696.02},
{datetime: '09:05', value: '2088225.04'},
{datetime: '09:25', value: '2088505.21'}]
如何使图表从图表绘图的中心线开始?
您可以使用
tickPositioner
函数并根据需要计算 y 轴刻度的位置。例如:
yAxis: {
tickPositioner: function() {
const yAxis = this;
const series = yAxis.series;
const center = series[0].processedYData[0];
const minDiff = Math.abs(yAxis.min - center);
const maxDiff = Math.abs(yAxis.max - center);
const tickPositions = [];
let interval;
if (minDiff > maxDiff) {
interval = minDiff / 3;
} else {
interval = maxDiff / 3;
}
for (let i = center - interval * 3; i <= center + interval * 3; i += interval) {
tickPositions.push(+i.toFixed(2));
}
return tickPositions;
}
}
现场演示:https://jsfiddle.net/BlackLabel/79f3onq4/
API参考: https://api.highcharts.com/highcharts/yAxis.tickPositioner