Set highcharts y-axis min value to 0, unless there is negative data

Pryor74 picture Pryor74 · May 7, 2013 · Viewed 20.7k times · Source

I'm having an issue with highcharts where I have a number of different charts being generated by JSON calls.

For the majority of these charts I need the minimum y-axis value to be set at 0, however there are a couple of occasions where negative values need to be shown. How can I tell highcharts to have a minimum y-axis value of 0 only if there are no negative values in the data, is this even possible?

Thanks

Answer

Yoav Kadosh picture Yoav Kadosh · Dec 12, 2016

The option that you're looking for is called softMin and was introduced in version 5.0.1. The docs describe it as follows:

A soft minimum for the axis. If the series data minimum is greater than this, the axis will stay at this minimum, but if the series data minimum is lower, the axis will flex to show all data.

yAxis: {
    softMin: 0
}

http://api.highcharts.com/highcharts/yAxis.softMin