我有下面的JSON數據,通過它我嘗試使用AngularJS創建折線圖。但是使用地圖功能,我能夠獲得$scope.labels
,但無法形成$scope.series
和$scope.data
。使用json數據創建圖表
這裏是我的JS代碼:
var source = [
{"DE":2,"NP":20,"BD":28,"TW":1,
"end_time":"2016-07-05T07:00:00+0000","date":"01-01-2011"},
{"DE":5,"NP":11,"BD":22,"BE":2,"FJ":2,
"end_time":"2016-07-06T07:00:00+0000","date":"01-09-2011"},
{"DE":5,"NP":24,"BD":29,
"end_time":"2016-07-07T07:00:00+0000","date":"01-11-2011"}
]
var $scope = {};
$scope.labels = [];
$scope.data = [];
$scope.series = [];
source.forEach(function(item){
$scope.labels.push(item.end_time)
})
如何來從JSON數據,形成一系列像下面和數據。
$scope.series = ["DE","NP","BD","TW"]
$scope.data = [] ---> //Stuck here in forming data
您應該只查看angular的文檔。有一個名爲$ http的模塊,並且有很多示例如何做你想要的。 以下是$ http的地址doc https://docs.angularjs.org/api/ng/service/$http –