简体   繁体   English

元素出现AngularJs Chart.js

[英]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. 我被困在这里,我正在将json提取到智能表中并从该表生成图表,我想进行交叉过滤,因此当应用过滤器时,图表会根据表上可见的数据进行更新。

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的最简单方法。感谢您的帮助

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

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