Highcharts - Keep Zero Centered on Y-Axis with Negative Values

前端 未结 5 826
灰色年华
灰色年华 2021-02-13 03:18

I have an area chart with negative values. Nothing insanely different from the example they give, but there\'s one twist: I\'d like to keep zero centered on the Y axis.

5条回答
  •  情话喂你
    2021-02-13 04:13

    Here is my solution. The nice thing about this is that you can maintain the tickInterval.

      tickPositioner(min, max) {
        let { tickPositions, tickInterval } = this;
        tickPositions = _.map(tickPositions, (tickPos) => Math.abs(tickPos));
        tickPositions = tickPositions.sort((a, b) => (b - a));
    
        const maxTickPosition = _.first(tickPositions);
        let minTickPosition = maxTickPosition * -1;
    
        let newTickPositions = [];
        while (minTickPosition <= maxTickPosition) {
          newTickPositions.push(minTickPosition);
          minTickPosition += tickInterval;
        }
    
        return newTickPositions;
      }
    

提交回复
热议问题