[英]Use Highcharts-ng with JSON
For display the chart, y use the tipical way: 要显示图表,请使用典型方式:
var myapp = angular.module('myapp', ["highcharts-ng"]);
myapp.controller('myctrl', function ($scope) {
$scope.highchartsNG = {
options: {
chart: {
type: 'bar'
}
},
series: [{
data: [10, 15, 12, 8, 7]
}],
title: {
text: 'Hello'
},
loading: false
}
});>
But i want load the data from a remote json. 但我想从远程json加载数据。
I tried using the method described in the official documentation, but with angular it does not work. 我尝试使用官方文档中描述的方法,但是使用角度方法不起作用。 I'm using highchart-ng but i dont know how to load remote JSON-Files.
我正在使用highchart-ng,但我不知道如何加载远程JSON文件。
I'm researching how to use $http.get but still i dont know how to use it. 我正在研究如何使用$ http.get,但我仍然不知道如何使用它。
Thanks! 谢谢!
Change the Data ofr your chart to be within a variable: 将图表的数据更改为变量内:
var chartData = [];
[...]
series: [{
data: chartData
}],
[...]
Then you can use the $http-Service like the following: 然后,您可以像下面这样使用$ http-Service:
$http.get('/PATH/TO/MY/JSON')
.success(function(jsonData){
// Do some remodeling of the jsonData if necessary, else just give it to the chart:
chartData = jsonData;
}
The $http
-Service of Angular works promise based - this means that you provide the callback of the request within .success
and .error
-Functions. $http
Angular的.success
这意味着您可以在.success
和.error
.success
提供请求的回调。 Its pretty good explained in the official docs . 官方文档中对此进行了很好的解释。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.