无法从$ scope.data更新ChartJS数据

时间:2016-07-04 12:03:48

标签: angularjs charts

我想使用AngularJS动态更新Chartjs图表的数据。如果没有更新数据,图表工作正常,但如果我尝试使用$ interval函数更新数据,则图表将保持空白。

   $scope.labelsx2 = [];
    $scope.seriesx2 = [];
    $scope.datax2 = [
        [65, 59, 80, 81, 56, 55, 40]
    ];  

    $scope.randomize = function () {


         $scope.datax2 = [65, 59, 1, 81, 1, 55, 1];
         console.log('workk');


    };

    $interval(function() {$scope.randomize();},1000,0);


    <div class="item item-text-wrap">

        <canvas id="line" class="chart chart-line" data="datax2" labels="labelsx2" legend="true" series="seriesx2" options="{showTooltips: false}"></canvas>

    </div>

1 个答案:

答案 0 :(得分:0)

更改

$scope.datax2 = [65, 59, 1, 81, 1, 55, 1];

在随机函数中

$scope.datax2 = [[65, 59, 1, 81, 1, 55, 1]];