change marginLeft and marginRight from a javascript statment using highcharts

老子叫甜甜 提交于 2019-12-13 00:22:55

问题


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.


回答1:


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/



来源:https://stackoverflow.com/questions/26547500/change-marginleft-and-marginright-from-a-javascript-statment-using-highcharts

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!