Я пытаюсь сделать круговую диаграмму в Angularjs, используя высокие графики. Диаграмма не отображает данные. На ней отображаются жестко закодированные данные (там, где они отмечены в коде), но не отображаются динамические данные в формате json.
Мой HTML-шаблон
<div style="min-width: 310px; height: 400px; max-width: 600px; margin: 0 auto; margin-top:100px;">
<hc-pie-chart title="Employee from diffrent states" data="pieData">Placeholder for pie chart</hc-pie-chart></div>
Мой контроллер и директива
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:.1f} %'
}
}
},
series : [ {
data : scope.data
} ]
});
}
};
})
app.controller("highChartController", function($scope,$state, $window,$timeout,$stateParams,chartService)
StateList();
function StateList() {
var getData=chartService.getStateList()
getData.then(function(emp) {
var data= emp.data;
$scope.pieData=data; //if i will put hardcoded data here it will not work
});
//if i will put hardcoded data here it will work
}
});
Мой файл json
var data=[{name: "Bihar", y: 1},{name: "Karnataka", y: 3},{name: "Bengal", y: 2},{name: "Punjab", y: 3},{name: "Maharastra", y: 2}]