使用Highcharts,我怎样才能更改图表marginLeft和marginRight,然后从javascript语句重绘它。 我需要在我的代码中的某些地方重新调整图表边距。
我尝试过类似的事情:
test = $('#container').highcharts();
test.margin[4] = 50;
test.redraw();
但它不起作用。
答案 0 :(得分:1)
一般情况下,它不受支持,但有点愚蠢的做法:
//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();
首先:它的保证金[1],而不是保证金[4]。边距为:0-top,1-right,2-bottom,3-left。就像在CSS中一样。
然后我们需要告知Highcharts需要重新绘制轴,因此我们将所有isDirty
标志设置为true。
我们也可以使用test.xAxis[0].update()
代替test.redraw()
。这将迫使所有轴回流。