HighCharts: How to use reflow to allow auto-resize after changing size

前端 未结 2 1808
渐次进展
渐次进展 2020-12-16 05:51

In our Angular app we\'re using highcarts-ng for our HighCharts implementation.

Here is the Chart Maximize and Minimize function, which works:

functi         


        
2条回答
  •  暖寄归人
    2020-12-16 06:45

    You can do this by adding a new method to chart that will manually trigger the reflow like so:

    chart.reflowNow = function(){
        this.containerHeight = this.options.chart.height || window.window.HighchartsAdapter.adapterRun(this.renderTo, 'height');
        this.containerWidth = this.options.chart.width || window.window.HighchartsAdapter.adapterRun(this.renderTo, 'width');
        this.setSize(this.containerWidth, this.containerHeight, false);
        this.hasUserSize = null;
    }
    

    Then whenever you want to get away from manual resizing using setSize() just call chart.reflow()

    Here's an working example: jsFiddle

    Reference taken from: github-issue

    UPDATE for ng-highcharts users

    For doing this when using ng-highcharts library, you can simply pull out the chart object in the controller that has highcharts-ng dependency and add the reflowNow function, like so:

    var chart = this.chartConfig.getHighcharts();
    chart.reflowreflowNow = function (){ ... }
    

    This is also the recommended way to pull out chart to do custom jobs by author of ng-highcharts as noted here and this fiddle.

提交回复
热议问题