0

我以 JSON 格式获取数据

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

我如何使用带有 angular-js 的 AmCharts 饼图/圆环图绘制 JSON。

4

1 回答 1

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();
于 2015-03-13T08:51:20.680 回答