I'm trying to make a toggle button where you can freeze the scale. If you click again the scale is reputed automaticlly (which is default in highcharts).
Accoridng to the API reference, if y-axis = {max:null}
then the scale is automatic. But if I lock the scale I must extract the y-axis scale somehow so I can manually set the y-axis to the current value. And when I toggle back the y-axis is set to null.
Is there anyway to extract the y-axis scale when it is set to null? I haven't been able to find any in API.
Here is my highchart object
chartFactory.getBarChart = function(data, duration){
//console.log(chartData);
var chart = $('.chart').highcharts({
chart: {
renderTo: 'chartContainer',
type: 'column',
height: windowHeight - 220, //Set chartsize depending on size of window
reflow: true
},
title: {
text: "title"
},
subtitle: {
text: "Source: "
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
},
yAxis: {
min: 0,
max: null,
title: {
text: 'Energy (kWh)'
}
},
"tooltip": {},
plotOptions: {
column: {
animation: {
duration: duration
},
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: data //Calculated data
})
.highcharts(); // return chart
}
I'm trying to make a toggle button where you can freeze the scale. If you click again the scale is reputed automaticlly (which is default in highcharts).
Accoridng to the API reference, if y-axis = {max:null}
then the scale is automatic. But if I lock the scale I must extract the y-axis scale somehow so I can manually set the y-axis to the current value. And when I toggle back the y-axis is set to null.
Is there anyway to extract the y-axis scale when it is set to null? I haven't been able to find any in API.
Here is my highchart object
chartFactory.getBarChart = function(data, duration){
//console.log(chartData);
var chart = $('.chart').highcharts({
chart: {
renderTo: 'chartContainer',
type: 'column',
height: windowHeight - 220, //Set chartsize depending on size of window
reflow: true
},
title: {
text: "title"
},
subtitle: {
text: "Source: "
},
xAxis: {
categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun','Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
},
yAxis: {
min: 0,
max: null,
title: {
text: 'Energy (kWh)'
}
},
"tooltip": {},
plotOptions: {
column: {
animation: {
duration: duration
},
stacking: 'normal',
dataLabels: {
enabled: true,
color: (Highcharts.theme && Highcharts.theme.dataLabelsColor) || 'white'
}
}
},
series: data //Calculated data
})
.highcharts(); // return chart
}
Share
Improve this question
edited Aug 11, 2013 at 11:48
Joe
asked Aug 11, 2013 at 11:43
JoeJoe
4,26432 gold badges106 silver badges180 bronze badges
1
- Can you possibly post here relevant parts of the code you already have? – Petr R. Commented Aug 11, 2013 at 11:45
1 Answer
Reset to default 5Sure, you can extract the current chart settings by calling chart.highcharts(), it contains each axis which will have the effective min and max as well as the data's min/max set based on the series that are using it.
yAxis[0] would work if you only have one, but setting an id on the Axis might be clearer:
var chart = highcharts({...
yAxis: {
id: 'my_y',
...
yAxis = chart.highcharts().get('my_y');
yAxis.getExtremes(); // {min:, max:, dataMin:, dataMax:}
yAxis.setExtremes(newmin, newmax);
fiddle