简体   繁体   English

角高图重绘

[英]Angular Highcharts redraw

How can i trigger a redraw in the angular highcharts directive? 我该如何在角度highcharts指令中触发重绘? The problem is i have contained my chart in a tab and it initializes badly. 问题是我已将我的图表包含在选项卡中,并且初始化严重。 Like this : http://puu.sh/lVg8s/6d9e9f2083.png 像这样: http : //puu.sh/lVg8s/6d9e9f2083.png

If i resize the window it fixes itself for the selected tab instance, but i need to somehow do that as it loads up. 如果我调整窗口的大小,它会为选定的选项卡实例自行修复,但是在加载时我需要采取某种措施。

Application.controller('SalesReportsHistoryController', ['ServerActions', '$scope', 'initData', function( ServerActions, $scope, initData ){

    var history = this;

    history.initData = initData.data;

    $scope.$on('$viewContentLoaded', function () {
        $(window).resize(function () {
            console.log('resized!');
        });

        $(window).resize();
    });

... etc more code

This is what i tried, but no dice. 这是我尝试过的,但没有骰子。 The resize event fires, and if i fire it in the console it works as i expect, but not on load. 调整大小事件触发,如果我在控制台中触发它,则按预期运行,但不加载。

I suppose that you have full control over your data and know precisely when it's available or not. 我想您对数据有完全的控制权,并且确切地知道什么时候可用。 If the answer is yes, you can add an ng-if directive on the highcharts directive that triggers the repaint. 如果答案是肯定的,则可以在highcharts指令上添加ng-if指令,以触发重新绘制。

<div ng-if="showChart">
    <highchart></highchart>
</div>

Then in your controller then you can set $scope.showChart to either true or false depending on the availability of the chart's data. 然后,在控制器中,您可以根据图表数据的可用性将$ scope.showChart设置 true或false。 If that does not work, you can always set a timeout on $scope.showChart so it will be true only after whole DOM has been rendered. 如果这不起作用,则始终可以在$ scope.showChart上设置超时,因此只有在呈现整个DOM之后它才为真。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM