简体   繁体   中英

Element occurrences AngularJs Chart.js

I am quite stuck here, I am fetching a json into a smart table and generating charts from that table, I want to have cross filtering so when a filter is applied the chart updates according to the data visible on the table.

The chart should represents the status of order, The status can be : "Work in progress" "Pending" "Approved" ... I tried to write different functions to count every element occurences but none of them worked:

My code now

 $scope.$watch(function() { $scope.zdata = $scope.displayed; $scope.labels = []; $scope.data = []; $scope.updatedata = function() { //var a = getCount('Approved'); //$scope.zdata.forEach(function (zdata) { $scope.labels.push('Approved', 'Awaiting Verification', 'Work In Progress'); $scope.data.push('20', '15', '3'); // $scope.labels.push(zdata.Status); // $scope.data.push(zdata.Status.length); // }); }; 
 <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script> 

Currently I am showing dummy data just to explain the point. Thanks a million in advance

use instead:

$scope.labels = []; // -> $scope.labels.splice(0);
$scope.data = []; // -> $scope.data .splice(0);
//... something else

修复了使用Underscore.js的最简单方法。感谢您的帮助

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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