Using Highcharts, how can I only change the chart marginLeft and marginRight and then redraw it from a javascript statement.
I need to re-adjust the chart margin in some places in my code.
http://jsfiddle.net/ovh9dwqc/
I tried something like:
test = $('#container').highcharts();
test.margin[4] = 50;
test.redraw();
But it didn't work.
In general it's not supported, but a little hacky way to do it:
//JAVASCRIPT code to change left and right margin
test = $('#container').highcharts();
$.each(test.axes, function(i, e) {
e.isDirty = true;
});
test.margin[1] = 50;
test.redraw();
First: it's margin[1], not margin[4]. Margins are: 0-top, 1-right, 2-bottom, 3-left. Just like in CSS.
Then we need to inform Highcharts that axes needs to be redrawn, so we are setting for all of them isDirty
flag to true.
We could also use test.xAxis[0].update()
instead test.redraw()
. That will force all axes to reflow.
Live demo: http://jsfiddle.net/ovh9dwqc/1/