How can I force multiple y-axis in Highcharts to have a common zero

后端 未结 7 1408
萌比男神i
萌比男神i 2021-01-02 00:32

See this JSFiddle. How do I get the y-axis zero to align?

7条回答
  •  时光取名叫无心
    2021-01-02 00:35

    I've had issue with all the answers as it didn't support values on negative Y axis. To center on 0, i applied below logic

    Find min/max of the series and pad it so 0 comes in center

    if(max > 0  && min < 0){
    {
       const diff = max + min;
       if(diff > 0){
          min = min - diff
       }
       else{
          max = max + -1 * diff
       }
    } 
    else if (max > 0){
       max = min * -1
    }
    else{
       min = max * -1
    }
    

    Then when defining axis on chart, use the min/max values from above, this will ensure 0 shows in center

提交回复
热议问题