2
I created a Plunker with a working example. To simplify I only pull the data (not the labels, etc.), but that is easy to complete.
我用一个工作示例创建了一个插入器。为了简化,我只提取数据(而不是标签等),但这很容易完成。
In the controller, we assign vm to this and in the function getData I reference vm.data. Before you had $scope which is a different $scope in the function that the one you assign as a blank array.
在控制器中,我们为它分配vm,在函数getData I中引用vm.data。在您拥有$scope之前,它是函数中的一个不同的$scope,您将其赋值为一个空白数组。
.controller('MyCtrl', ['$scope', 'HRDataPointFactory', function($scope, HRDataPointFactory) {
var vm = this;
//The following lines cause the chart to populate, but obviously I dont care about this fake data.
vm.labels = ["January", "February", "March", "April", "May", "June", "July"];
vm.series = ["Series A", "Series B"];
// vm.data = [
// [65, 59, 80, 81, 56, 55, 40],
// [28, 48, 40, 19, 86, 27, 90]
// ];
vm.OnClick= function(points, evt) {
console.log(points, evt);
};
vm.data = [
[]
];
vm.getData = function() {
HRDataPointFactory.getData($scope.department, $scope.dt1, $scope.dt2)
.then(function(success) {
console.log(JSON.stringify(success));
vm.data = success.data;
});
}
vm.getData();
/*unrelated stuff here*/
}])
I print in the console the data I receive:
我在控制台打印我收到的数据:
{"data":[[65,59,80,81,56,55,40],[28,48,40,19,86,27,90]],"status":200,"config":{"method":"GET","transformRequest":[null],"transformResponse":[null],"params":{},"url":"data","headers":{"Accept":"application/json, text/plain, */*"}},"statusText":""}
The data is hosted on plunker too using this as a format:
数据也作为一种格式托管在柱塞上:
[
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
]
Please not that I also used the "Controller as" syntax in the HTML to respect best practices... see john papa's article on this subject.
请不要让我在HTML中使用“Controller as”语法来尊重最佳实践……看看约翰爸爸关于这个问题的文章。
Let us know.
让我们知道。