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

前端 未结 2 1806
渐次进展
渐次进展 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:36

    I ended up finding an alternative solution to be the only thing I could get working, and it actually was pretty simple and straight forward to do. In case anyone else is looking for a fix for this, here's links to the resources that were useful and solved the issue for me.

    You can simply add this to your chart config object, at the same level as the config.series or config.options. The comment references info but the actual solution that worked for me uses $timeout with 0 seconds, here

    *For using highcharts-ng obviously

    http://plnkr.co/edit/14x7gfQAlHw12XZVhWm0?p=preview

    $scope.chartConfigObject = {
    
        // function to trigger reflow in bootstrap containers
        // see: http://jsfiddle.net/pgbc988d/ and https://github.com/pablojim/highcharts-ng/issues/211
        func: function(chart) {
            $timeout(function() {
                chart.reflow();
                //The below is an event that will trigger all instances of charts to reflow
                //$scope.$broadcast('highchartsng.reflow');
            }, 0);
        }
    };
    
    0 讨论(0)
  • 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.

    0 讨论(0)
提交回复
热议问题