Highcharts: Ensure y-Axis 0 value is at chart bottom

后端 未结 8 1813
名媛妹妹
名媛妹妹 2021-02-05 02:18

I\'m outputting a series of highcharts on a page. In some instances, all data for the specified time period may come back with 0 values.

In such a case, the chart looks

8条回答
  •  遇见更好的自我
    2021-02-05 02:57

    Here is a fix I came up with that doesn't require any preprocessing of the data and just let highcharts do it, like it used to before the update. http://jsfiddle.net/QEK3x/

    if(chart.yAxis[0].dataMax === 0)
    {
       chart.yAxis[0].setExtremes(0, 5);
    }
    

    You only need to check the first series axis, as if the first one is not 0 then the problem won't occur. I might submit a pull request for this to high-charts, though I kinda feel like they intended for this functionality for some reason.

提交回复
热议问题