I'm trying to set a minimum upper bound, specifically:
- The Y axis should start at 0
- The Y axis should go to at least 10, or higher (automatically scale)
- The upper bound for the Y axis should never be less than 10.
Seems like something Highcharts does, but I can't seem to figure out how. Anybody have experience with this?
A way to do this only using options (no events or functions) is:
Here
minRange
defines the minimum span of the axis.maxPadding
defaults to 0.01 which would make the axis longer than 10, so we set it to zero instead.This yields the same results as a
setExtreme
would give. See this JSFiddle demonstration.Adding to Julian D's very good answer, the following avoids a potential re-positioning problem if your calculated max varies in number of digits to your desired upper bound.
In my case I had percentage data currently going into the 20's but I wanted a range of 0 to at least 100, with the possibility to go over 100 if required, so the following sets min & max in the code, then if dataMax turns out to be higher, reassigns max up to it's value. This means the graph positioning is always calculated with enough room for 3-digit values, rather than calculated for 2-digits then broken by squeezing "100" in, but allows up to "999" before there would next be a problem.
Highcharts doesn't seem to have an option for doing this at chart creation time. However, they do expose a couple methods to interrogate the extremes and change the extremes,
getExtremes()
andsetExtremes(Number min, Number max, [Boolean redraw], [Mixed animation])
found in their documentation.So, a possible solution (after chart creation):
yAxis[0]
references the first y-axis, and I'm assuming that you only have one axis in this case. The doc explains how to access other axes.This isn't ideal, because the chart has to redraw which isn't too noticeable, but it's still there. Hopefully, Highcharts could get this sort of functionality built in to the options.
HigtCharts has a really good documentation of all methods with examples.
http://www.highcharts.com/ref/#yAxis--min
In your case I think you should the "min" and "max" properties of "yAxis".
If you are creating your chart dynamically you should set
min=0 max=10 , if your all data values are less then 10
and
only min=0, if you have value greater then 10
Good luck.
Try setting the minimum value of the axis and the interval of the tick marks in axis units like so:
Also don't forget to set the max value.
Hope that helps.