highcharts 如何在Highchart js中使图表从图表的中心线开始?

rjzwgtxy  于 12个月前  发布在  Highcharts
关注(0)|答案(1)|浏览(208)

我在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'}]

字符串
如何使图表从图表中心线开始绘制?

sd2nnvve

sd2nnvve1#

您可以使用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

相关问题