Dynamically modifying the HighChart layout options

别来无恙 提交于 2019-12-24 09:58:12

问题


I can't find way to update marginTop value of already created chart.

Check out my example:

http://jsfiddle.net/TZaEV/4/

var btn = $('#btn');
btn.click(function(){
// do changes
});

I need to change chart.marginTop value without creating chart object again. (When I click on trigger button, for example).


回答1:


var btn = $('#btn');
btn.click(function(){
    chart.optionsMarginTop += 20;
    chart.isDirtyBox = true; // this makes your chart redraw
    chart.redraw();
});

Demo




回答2:


This one worked for me:

const chart = $("#container").highcharts();
chart.options.chart.marginTop = 100;
chart.isDirtyBox = true;
chart.redraw();



回答3:


How about using Chart.update() function?

chart.update({
  chart: {
    marginTop: 30
  }
});

API Reference:
http://api.highcharts.com/highcharts/Chart.update http://api.highcharts.com/highcharts/chart.marginTop

Example:
http://jsfiddle.net/neo0xb2w/



来源:https://stackoverflow.com/questions/14947484/dynamically-modifying-the-highchart-layout-options

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