Reputation: 7
I am trying to get a simple axis update to work through a button on highstocks, with the plan of "hiding" a data series/yaxis out of view when you hit a button, and then reducing the chart's height by that amount. For the life of me I just cannot get the button to work. If I manually put the setting of "top: -300" into the second y axis it works. Where is this going wrong?
jsfiddle:
http://jsfiddle.net/abbike18/Ww5Tg/3/
var chart = $('#container').highcharts();
$('#hide').click(function() {
chart.yAxis[1].update({
top: -300
});
chart.setSize(chartHeight = chartHeight -100);
});
Upvotes: 0
Views: 59
Reputation: 45079
First of all, you create variable chart
before chart is initialized. Move that line inside the button, will be better. Second, you didn't created chartHeight variable anywhere. Last thing, is to redraw chart only once (in setChart function), so disable redraw for yAxis.update()
.
See working demo: http://jsfiddle.net/Ww5Tg/4/
And code:
var chartHeight = 500;
$('#hide').click(function() {
var chart = $('#container').highcharts();
chart.yAxis[1].update({
top: -300
}, false);
chartHeight -= 100;
chart.setSize(null, chartHeight);
});
Upvotes: 1