每秒添加点的图表

highcharts-ng addpoint each second

我有一个实时数据样条(每秒更新一次) 但我会用 angular 应用程序

做同样的事情

(我想这样做:http://www.highcharts.com/demo/dynamic-update 在我的 angular 应用程序中使用 highcharts-ng。)

没有 angular 我有:

events: {
                load: function () {

                    var series = this.series[0];
                    setInterval(function () {
                        var x = (new Date()).getTime(), // now
                            y = Math.random()*180;
                        series.addPoint([x, y], true, true);
                    }, 1000);
                }
            }

但是 angular 我尝试用 $scope 编码来做这个......这什么都不做:/

 var series = $scope.series[0];
 setInterval(function () {
        var x = (new Date()).getTime() // now
      var y = Math.random();
        series.addPoint([x, y], true, true);
    }, 1000); 
};

这里 fiddle : http://jsfiddle.net/c58b1z6b/10/

感谢帮助

我认为通过在 setInterval 函数中添加 $scope.$apply 的小改动,您将能够获得预期的结果:

     setInterval(function () {
        var x = (new Date()).getTime() // now
        var y = Math.random()*180;
        $scope.$apply(function() {
           //series.addPoint([x, y], true, true);
           series.data.push(y);
        })
    }, 1000); 

我已经注释掉了对 addPoint() 的原始调用,因为结果与我预期的不太一样...