Reputation: 153
I trying to give correct parametrs to draw charts with ng-repeat
:
here is HTML:
<tr ng-repeat="perspective in perspectives">
<td>
<div class="hc-pie" items="values"></div>
</td>
<td>{{perspective.perfomance}}</td>
<td>{{perspective.current}}</td>
<td>{{perspective.previous}}</td>
<td>{{perspective.variance}}</td>
</tr>
and controller:
$scope.perspectives=[
{perfomance:'AAA',
current:'a',
previous:'b',
variance:'c',
plus:false,
graphData:[
['value', 32.4],
['value', 13.2],
['value', 84.5],
['value', 19.7],
['value', 22.6],
['value', 65.5],
['value', 77.4],
['value', 90.4],
['value', 17.6],
['value', 59.1],
['value', 76.8],
['value', 21.1]
]
];
and directive:
.directive('hcPie', function () {
return {
restrict: 'C',
replace: true,
scope: {
items: '='
},
controller: function ($scope, $element, $attrs) {
},
template: '<div id="container" style="margin: 0 auto">not working</div>',
link: function (scope, element, attrs) {
var chart = new Highcharts.Chart({
chart: {
renderTo: element[0],
type: 'column',
backgroundColor: null
},
title: {
text: null
},
subtitle: {
text: null
},
xAxis: {
categories: [
'Jan',
'Feb',
'Mar',
'Apr',
'May',
'Jun',
'Jul',
'Aug',
'Sep',
'Oct',
'Nov',
'Dec'
],
labels: {
enabled: false
},
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
tickLength: 0
},
yAxis: {
gridLineWidth: 0,
minorGridLineWidth: 0,
lineColor: 'transparent',
min: 0,
title: {
text: null
},
labels: {
enabled: false
}
},
tooltip: {
enabled: false
},
plotOptions: {
column: {
pointPadding: 0,
borderWidth: 0,
states: {
hover: {
color: '#FFFFFF'
}
}
}
},
legend: {
enabled: false
},
series: [{
name: 'Value',
color: '#EC5B00',
data: scope.items
}]
});
scope.$watch("items", function (newValue) {
chart.series[0].setData(newValue, true);
}, true);
}
}
});
there isn't any mistakes in console, but I can't diplay charts what I mised?
Upvotes: 0
Views: 40
Reputation: 4769
Update see the working fiddle here
There are two mistakes. First is : your array isn't closing properly. Second is : you need to use perspective.graphData instead value in div with hc_pie. In controller :
$scope.perspectives=[
{perfomance:'AAA',
current:'a',
previous:'b',
variance:'c',
plus:false,
graphData:[
['value', 32.4],
['value', 13.2],
['value', 84.5],
['value', 19.7],
['value', 22.6],
['value', 65.5],
['value', 77.4],
['value', 90.4],
['value', 17.6],
['value', 59.1],
['value', 76.8],
['value', 21.1]
]
}
];
and in html use following
<table><tr ng-repeat="perspective in perspectives">
<td>
<div class="hc-pie" items="perspective.graphData"></div>
</td>
<td>{{perspective.perfomance}}</td>
<td>{{perspective.current}}</td>
<td>{{perspective.previous}}</td>
<td>{{perspective.variance}}</td>
</tr></table>
Upvotes: 1