【发布时间】:2017-11-11 07:14:45
【问题描述】:
我正在使用 highChart 和 angularJS 制作图表。 我关注这个highChart。
这是我的代码:
-
AngularJS:
app.directive('hcPieChart', function () { return { restrict: 'E', template: '<div></div>', scope: { title: '@', data: '=' }, link: function (scope, element) { Highcharts.chart(element[0], { chart: { type: 'pie' }, title: { text: scope.title }, plotOptions: { pie: { allowPointSelect: true, cursor: 'pointer', dataLabels: { enabled: true, format: '<b>{point.name}</b>: {point.percentage:.2f} %' } } }, series: [{ data: scope.data }] }); } }; }); app.controller('ChartsController', function ($scope) { var ids =location.search; $scope.Stats=function(){ $http.get(url+"/Stats"+ids) .success(function(data){ $scope.Stat = data; }).error(function(err,data){ console.log("error:" +data); }); }; $scope.Stats(); /*$scope.Stat = [{ "Validate":17.456789, "NotValidate":2.96296, "Nb_V":2.96296, "Nb_Not_v":2.96296 }]; */ // Sample data for pie chart $scope.pieData = [{ name: 'CheckLists Socred', y: $scope.Stat[0].Validate, color: '#00c853' },{ name: 'CheckLists Not Socred', y: $scope.Stat[0].NotValidate, color: '#b71c1c' }]; }); HTML 代码:
<html > <head> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.5/angular.min.js"></script> <script type="text/javascript" src="https://code.highcharts.com/highcharts.js"></script> </head> <body ng-app="app" ng-controller="ChartsController" > <hc-pie-chart title="Browser usage" data="pieData">Placeholder for pie chart</hc-pie-chart> </body> </html>
当来自图表海报时,我有这个问题:
未捕获的类型错误:无法读取未定义的属性“parentGroup” 在 k.setState (App/Template/highcharts/highcharts.js:392:112) 在 App/Template/highcharts/highcharts.js:207:54 在 Array.forEach (本机) 在 a.each (App/Template/highcharts/highcharts.js:27:360) 在 a.Pointer.runPointActions (App/Template/highcharts/highcharts.js:207:32) 在 k.onMouseOver (App/Template/highcharts/highcharts.js:389:130) 在 SVGGElement.c (App/Template/highcharts/highcharts.js:380:323)
谢谢你帮助我,
【问题讨论】:
-
你能在 jsfiddle 例子中重现它吗? (你可以从类似的东西开始:jsfiddle.net/6vayegnk)
-
我使用了 jsfiddle,但无法正常工作 jsfiddle
-
当你让它工作时告诉我。或者您可以使用其他工具,例如 plunker 等。
-
我认为不是工具问题。但是代码中有问题plnkr
-
你的 script.js 是空的......你的 html 标签也有问题。
标签: angularjs html highcharts