如何在不同图表

时间:2016-05-24 12:07:44

标签: angularjs angularjs-directive highcharts angularjs-controller

app.controller("myCtrl", function($scope) {
	
$scope.perspectives = [{
     title : 'Depression Remission at 12 Months CMS159v4',
     graphData: [34,2,5,5,2,1,10]
  },
  {
    title : 'Comprehensive Diabetes Care: HbA1c Poor Control (>9.0%)',
    graphData: [2,7,9,25,55,20]
   },
  {
   title : 'Screening for Clinical Depression and follow-up',
    graphData: [2,7,9,25,55,20]
  },
   {
  title : 'Tobacco Assessment and Counseling',
    graphData: [2,7,9,25,55,20]
  },
   {
    title : 'Alcohal AND Drug Misuse(SBIRT)',
    graphData4: [2,7,9,25,55,20]
  }];
  



 
  $scope.processed = $scope.perspectives[0].graphData.map(function(elem,i){
	
	return [i,elem];
	  
  });

  
 
})
This is My controller from where i am passing array for title and value for different linechart. i have directive where i have Highchart.chart constructor where i putting all chart object.
<div ng-repeat="perspective in perspectives">
          <highcharts-pie class="hc-pie" items="processed" title="perspective.title"></highcharts-pie>
      </div>

这是我处理的html页面是我的函数名称,它有硬编码参数,所以我只得到所有折线图中的第一个数组对象。我希望graphData数组可以放入不同的线图。

提前谢谢

2 个答案:

答案 0 :(得分:2)

“已处理”对象是在“perspectives”对象的第0个元素上定义的。

$scope.perspectives[0]

您应该创建一个函数并将index / perspectives对象传递给该函数,并获取特定于该函数的项列表。

控制器中的功能:

$scope.getItems=function(perspective){
   return perspective.graphData.map(function(elem,i){
      return [i,elem];
     });
}

在你看来:

<div ng-repeat="perspective in perspectives">
      <highcharts-pie class="hc-pie" items="getItems(perspective)" title="perspective.title"></highcharts-pie>
</div>

还要确保指令'highcharts-pie'中项目的绑定为'='。

答案 1 :(得分:0)

无需使用函数getItems(),

items =“perspective.graphData”//在body.html中也可以使用