使用highcharts更改javascript语句中的marginLeft和marginRight

change marginLeft and marginRight from a javascript statment using highcharts

本文关键字:marginLeft marginRight 语句 highcharts 更改 javascript 使用      更新时间:2023-09-26

使用Highcharts,如何只更改图表marginLeft和marginRight,然后从javascript语句中重新绘制。我需要重新调整代码中某些地方的图表边距。

http://jsfiddle.net/ovh9dwqc/

我试过类似的东西:

test = $('#container').highcharts();
test.margin[4] = 50;
test.redraw();

但它没有起作用。

一般来说,它不受支持,但有一种小技巧:

    //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-顶部,1-右侧,2-底部,3-左侧。就像在CSS中一样。

然后,我们需要通知Highcharts轴需要重新绘制,因此我们将所有轴的isDirty标志设置为true。

我们也可以用test.xAxis[0].update()代替test.redraw()。这将迫使所有轴回流。

现场演示:http://jsfiddle.net/ovh9dwqc/1/