score:5
It seems that there is no maxRange
equivalent (feature request, Torstein?) so that the axis maximum has to be determined before Highcharts is called. Building upon Sanath's suggestion a solution would be this:
$(function () {
var setA = [29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4];
var setB = [129.2, 144.0, 176.0, 135.6, 248.5, 316.4, 694.1, 795.6, 954.4, 1029.9, 1171.5, 1506.4];
var data = Math.random() < 0.5 ? setA : setB;
var height=Math.max.apply(Math, data);
if(height > 1000){ height = 1000; }
$('#container').highcharts({
chart: {
marginRight: 80 // like left
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: [{
lineWidth: 1,
max: height,
min: 0,
title: { text: 'yAxis' }
}],
series: [{
data: data
}]
});
});
As working example: http://jsfiddle.net/PanicJ/H2pyC/8/
score:1
$(function() {
$('#container').highcharts({
chart: {
marginRight: 80 // like left
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
},
yAxis: [{
lineWidth: 1,
max: 1000,
min: 0,
title: {
text: 'Primary Axis'
}
}, {
lineWidth: 1,
opposite: true,
title: {
text: 'Secondary Axis'
}
}],
series: [{
data: [29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4]
}]
});
$('#button').click(function() {
var chart = $('#container').highcharts();
if ($(this).hasClass('big')) {
$(this).removeClass('big');
chart.series[0].setData([29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4]);
chart.yAxis[0].setExtremes(0, 50);
} else {
$(this).addClass('big');
chart.series[0].setData([129.2, 144.0, 176.0, 135.6, 248.5, 316.4, 694.1, 795.6, 954.4, 1029.9, 1171.5, 1506.4]);
chart.yAxis[0].setExtremes(0, 1600);
}
});
});
This solution should work for you, you just need to set yAxis extremes for the chart, if you know the maximum data range for each series it would be easy, otherwise you need to calculate the maximum value for each series.
score:1
Since Highcharts 4.0 we can use yAxis.ceiling
and yAxis.floor
, demo.
Highcharts.chart('container1', {
yAxis: {
floor: 0,
ceiling: 100
},
series: [{
data: [-10, 1, 0, 2, 3, 5, 8, 5, 15, 14, 25, 154]
}]
});
score:4
please use setExtremes to define a range. The JSfiddle has been updated.
$('#button').click(function () {
var chart = $('#container').highcharts(
);
if ($(this).hasClass('big')) {
$(this).removeClass('big');
chart.series[0].setData([29.9, 11.5, 36.4, 19.2, 4.0, 46.0, 48.2, 15.2, 16.4, 4.1, 5.6, 44.4]);
//chart.setSize(null,100,true);
chart.yAxis[0].setExtremes(0,50);
} else {
$(this).addClass('big');
chart.series[0].setData([129.2, 144.0, 176.0, 135.6, 248.5, 316.4, 694.1, 795.6, 954.4, 1029.9, 1171.5, 1506.4]);
//chart.setSize(null,1600,true);
chart.yAxis[0].setExtremes(0,1600);
}
});
});
Source: stackoverflow.com
Related Query
- Highcharts - set maximum range for yAxis but keep axis dynamic within that range
- How to set a Maximum yAxis range for HighChart graph?
- My Highcharts graph with multiple axis ignores the max value I set for the first yaxis
- How to set Highcharts chart maximum yAxis value
- Highcharts Line - When Y axis min is set to 0, connecting line isn't shown for consecutive 0 values
- Set Dynamic x-axis range in Highcharts
- How do I put Icons in the y Axis for a Dynamic Highcharts chart?
- highcharts reversed yAxis but keep fill area below spline?
- Highcharts dynamic set category update the chart but shows only points but not lines
- Highcharts - Toggling the lines that run parallel to X axis for each value on Y axis?
- Dynamic Labels for X axis in HighCharts
- Highcharts - Automatic min/max range is not set correctly for 'area' and 'column' fill types
- Decimals on yAxis are not being displayed, even if that same code works on highcharts jsfiddle
- Set a minimal default range for a column chart in Highcharts
- How to keep highcharts speedometer within range
- HighCharts - Set default Axis options for my extension
- Showing all values on one point on x axis and changing range for rCharts highcharts
- How to set the width within axis label in highcharts
- Highcharts code with same set of code/data works in PHP but does not work in JSfiddle
- set different colors for each column in highcharts
- how to set the interval of points on Y - Axis highcharts
- HighCharts - How to create dynamic chart that exports EVERYTHING
- Highcharts - How to set custom colors for the series
- How do I set a minimum upper bound for an axis in Highcharts?
- how to set dynamic data in highcharts
- How to set a static minimum value for axes in Highcharts
- Highcharts - yAxis logarithmic scale and allowDecimals set to false not seeming to have any effect
- Highcharts column range change color for negative numbers
- Set x-axis range in highcharts
- Decimal values for yAxis categories in Highcharts
More Query from same tag
- Highchart only wants "y" element in JSON data?
- Highligligh particular areas based on X-axis data
- highchart x axis not showing correct date labels
- Changing data series type dynamically with Highcharts-angular
- Highcharts add series dynamically
- How to prevent cluttered date axis in Highcharts
- How can I move the datalabel in top right in variable pie chart
- Highcharts: tooltip Click instead of hover
- Exporting 2 button option issue in highchart
- Customize Highcharts tooltip
- Highchart stacked bar chart pagination
- how to use Kendo chart library in Server side
- Highchart: xAxis Label text not displayed when plotting 2 points
- Have some bars not a url link on highcharts
- Add more data into Highchart's column
- how to display 24 hours in xAxis on Highcharts
- How to get the correct the date-time format for highcharts in R (using rcharts)
- How to hide zero values in Column chart
- React highcharts, show legends as bar
- how to put some data option key url on Highchart?
- .NET Highcharts not applying responsive rules
- Trigger HighCharts Animation on View in Owl Carousel
- Position dataLabel above a certain column Highcharts
- Highcharts of type area range not displaying markers like circles
- Highcharts legend item hover event?
- Cannot find proper JSON array syntax for Highcharts
- Highcharts: Longer pie labels are chopped off
- HighChart for PHP 5.1 lower
- How to render overall data labels using highcharts?
- Highcharts - change pie slice color on existing chart