使用highcharts从javascript语句更改marginLeft和marginRight [英] change marginLeft and marginRight from a javascript statment using highcharts
问题描述
使用Highcharts,我怎样才能改变图表marginLeft和marginRight,然后从JavaScript语句重新绘制它。
我需要在代码中的某些地方重新调整图表边距。
我试过类似的东西:
test = $('#container')。highcharts();
test.margin [4] = 50;
test.redraw();
但它没有用。
解决方案
通常不支持, // JAVASCRIPT代码更改左右边距
test = $('#container')。highcharts();
$ .each(test.axes,function(i,e){
e.isDirty = true;
});
test.margin [1] = 50;
test.redraw();
第一:它是保证金[1],而不是保证金[4]。边距是:0顶,1右,2底,3左。就像在CSS中一样。
然后我们需要通知Highcharts轴需要重新绘制,所以我们设置它们全部 isDirty
标志为真。
我们也可以使用 test.xAxis [0] .update()
来代替 test.redraw()
。这将迫使所有轴回流。现在演示: http://jsfiddle.net/ovh9dwqc/1/
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.
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/
这篇关于使用highcharts从javascript语句更改marginLeft和marginRight的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!