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

前端 未结 5 821
灰色年华
灰色年华 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:00

    Just in case someone is searching,

    One option more. I ended up in a similar situation. Follows my solution:

    tickPositioner: function () {
        var dataMin,
        dataMax = this.dataMax;
        var positivePositions = [], negativePositions = [];
    
        if(this.dataMin<0) dataMin = this.dataMin*-1;
        if(this.dataMax<0) dataMax = this.dataMax*-1;
    
        for (var i = 0; i <= (dataMin)+10; i+=10) {
            negativePositions.push(i*-1)
        }
    
        negativePositions.reverse().pop();
    
        for (var i = 0; i <= (dataMax)+10; i+=10) {
            positivePositions.push(i)
        }
    
        return negativePositions.concat(positivePositions);
    
    },
    

    http://jsfiddle.net/j3NTM/21/

提交回复
热议问题