我使用angular d3指令从后端数据渲染饼图。 饼图适用于静态数据:
$http({
method : 'GET',
url : piechart_url,
headers:{
'Content-Type' :'application/json'
}})
.success(function(resp,status,headers,config) {
//try hard coded here
$scope.exampleData = [
{ key: "One", y: 5 },
{ key: "Two", y: 2 },
{ key: "Seven", y: 9 }
];
})
但它不适用于后端API的数据。 *它仅在饼图中呈现第一个键。 *
$http({
method : 'GET',
url : piechart_url,
headers:{
'Content-Type' :'application/json'
}})
.success(function(resp,status,headers,config) {
$scope.exampleData = resp.items;
})
resp.items包含
[{"key":"ONE","y":10000},{"key":"TWO","y":10}]
我尝试过添加/删除引号。