score:13
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()
and setExtremes(Number min, Number max, [Boolean redraw], [Mixed animation])
found in their documentation.
So, a possible solution (after chart creation):
if (chart.yAxis[0].getExtremes().dataMax < 10) {
chart.yAxis[0].setExtremes(0, 10);
}
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.
score:1
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".
min : Number The minimum value of the axis. If null the min value is automatically calculated. If the startOnTick option is true, the min value might be rounded down. Defaults to null.
max : Number The maximum value of the axis. If null, the max value is automatically calculated. If the endOnTick option is true, the max value might be rounded up. The actual maximum value is also influenced by chart.alignTicks. Defaults to null.
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.
score:1
Try setting the minimum value of the axis and the interval of the tick marks in axis units like so:
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container'
},
yAxis: {
min: 0,
max: 10,
tickInterval: 10
}
});
Also don't forget to set the max value.
Hope that helps.
score:3
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.
var chart = new Highcharts.Chart({
chart: {
renderTo: 'container',
events: {
load: function(event) {
thisSetMax = this.yAxis[0].getExtremes().max;
thisDataMax = this.yAxis[0].getExtremes().dataMax;
if (thisDataMax > thisSetMax) {
this.yAxis[0].setExtremes(0, thisDataMax);
alert('Resizing Max from ' + thisSetMax + ' to ' + thisDataMax);
}
}
}
},
title: {
text: 'My Graph'
},
xAxis: {
categories: ['Jan 2013', 'Feb 2013', 'Mar 2013', 'Apr 2013', 'May 2013', 'Jun 2013']
},
yAxis: {
min: 0,
max: 100,
title: {
text: '% Due Tasks Done'
}
}
//Etc...
});
score:10
A way to do this only using options (no events or functions) is:
yAxis: {
min: 0,
minRange: 10,
maxPadding: 0
}
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.
Source: stackoverflow.com
Related Query
- How do I set a minimum upper bound for an axis in Highcharts?
- How to set a static minimum value for axes in Highcharts
- how to set the interval of points on Y - Axis highcharts
- Highcharts - How to set custom colors for the series
- Highcharts - set maximum range for yAxis but keep axis dynamic within that range
- Highcharts Bar Chart - How to set the minimum bar width/length
- Highcharts Line - When Y axis min is set to 0, connecting line isn't shown for consecutive 0 values
- How to position labels for plotbands on y axis in Highcharts
- How do I put Icons in the y Axis for a Dynamic Highcharts chart?
- How To Show All Data Labels For Datetime Axis In Highcharts
- How can I set the alignment for individual axis labels in highcharts?
- Highcharts - how to set textShadow for data labels
- HighCharts - how to set labels font color for printing?
- Set minimum data interval for y axes on Highcharts
- Highcharts - How to set a gradient theme for each type of graph globally?
- How to set border for a highcharts pie?
- Can I set a minimum positive and a minimum negative axis value in Highcharts
- My Highcharts graph with multiple axis ignores the max value I set for the first yaxis
- Highcharts Theming: How to set gradient colors for certain chart types only?
- Highcharts how to make a set number of colors for pie chart data and drilldown data
- How to set xData as date (Y-M) for Highcharts synchronized charts?
- How to set up zoomType for Highcharts with the CodeIgniter lib
- How to set min start date for Highcharts plot?
- How can I update the data in highcharts for both x axis & y axis?
- How can I set the units on multiple axis on Highcharts
- how to set border radius for stacked bar in highcharts
- Highcharts Highmaps How to change value for color axis in map bubble
- How to set the x axis of HighCharts to intake DateRange
- How to set point in highcharts when x axis and y axis has data as text values?
- How to plot the X axis data point for uneven tick interval at in Highcharts
More Query from same tag
- How can I sort the stacked bar charts in Highcharts by the sum of positive response?
- Export Highcharts bubble lat/lon map trough their server
- Highcharts - show custom tooltip on mouseOver and on mouse Click
- Highcharts : is it possible to make specific plots of a series transparent.
- Highcharts - Issue with showing and hiding plot lines and bands on legendItemClick
- Highchart change the chart type in drilldown
- Tooltip descriptions hidden beneath buttons and tables
- HighChart Skipping the first point : Highcharts, Javascript
- How do I adjust the initial range in hc_navigator
- Include hidden series in exported CSV using Highcharts v8.0
- HighCharts getting data from database to outside js file
- How to hide series via the legend in highstock ?
- Highcharts dynamic stacked area
- Highcharts not displaying tooltip title properly
- Static Highcharts graphic with external csv data and dynamic footnote
- How can I extend the x-axis on a Highcharts graph?
- How to display specific years only on xAxis in a column-graph with Highcharts
- Get max of x axis in highcharts using react
- Color each point individually in column chart highcharts
- highcharts canvas-tools: Cannot read property 'prototype' of undefined
- Convert JSON data into format in Highcharts' basic line chart
- React highchart: Shared tooltip in same and different chart
- Highcharts multiple charts on a single page using c# asp.net mvc3
- Puppeteer Without an HTML page?
- How do I make npm pack "highcharts-export-server" wait for it to finish processing
- Highcharts: using Google Analytics to capture event actions for exporting the chart
- Pull HighCharts data labels to the right
- plot area width and height in HighCharts
- Highcharts numeric x-axis
- Loading variwide chart from Highcharts library in Angular 2+