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

2019-03-14 07:45发布

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 like this: http://jsfiddle.net/charliegriefer/KM2Jx/1/

There is only 1 y-Axis label, 0, and it's in the middle of the chart.

I'd like to force that 0 value for the y-Axis to be at the bottom of the chart, which would be consistent with other charts on the page that do have data.

Have tried various yAxis properties, such as "min: 0", "minPadding: 0", "maxPadding: 0", "startOnTick: true".

Seems it should be pretty straightforward, but I'm at a loss :(

Relevant yAxis code:

yAxis: {
    min: 0, 
    minPadding: 0, 
    startOnTick: true, 
    title: {
        text: ""
    }
},

标签: highcharts
8条回答
Emotional °昔
2楼-- · 2019-03-14 08:22

Just add "min" option

yAxis: {
   min: 0
}
查看更多
地球回转人心会变
3楼-- · 2019-03-14 08:26

I've found another (and very simple) solution:

You can set y-axis minRange property:

yAxis: {
    ...
    minRange : 0.1
}

This makes Highcharts render yAxis min and max values when all data is 0.

UPDATE:

Highcharts 4.1.9 fix also needs:

        plotOptions: {
            line: {
                softThreshold: false
            }
        }

updated js fiddle

查看更多
登录 后发表回答