如何使用动态数据(JSON)绘制amchart饼图

时间:2014-08-13 13:45:32

标签: angularjs pie-chart amcharts donut-chart

我在JSON中获取数据

{"Excellent":"5","NeedsImprovement":"14","Average":"9"}

如何使用AmCharts饼图/圆环图和angular-js绘制JSON。

1 个答案:

答案 0 :(得分:2)

var data = JSON.parse(JSON_TEXT);
var dataProvider = [];

for(var key in data) {
  dataProvider.push({
    value: data[key],
    title: key,
  });
}


var chart = AmCharts.makeChart("chartdiv", {
  "type": "pie",
  "theme": "none",
  "dataProvider": dataProvider,
  "titleField": "title",
  "valueField": "value",
  "labelRadius": 5,
  "radius": "42%",
  "innerRadius": "60%",
  "labelText": "[[title]]"
});

并且您应该更新数据

chart.dataProvider = newSetOfDataArray;
chart.validateData();