Fusionchart Angularjs 无法显示来自 URL 的 JSON 的图表
Fusionchart Angularjs cannot show Graph with JSON from URL
我使用 angular js 的融合图表。我的数据来自 json url 和 http angular(我的工厂),这里是我的 json 对象:
{"chart":{"caption":"Asset Hardware by Status","numberPrefix":"","dataFormat":"json","theme":"fint","showBorder":"0","borderAlpha":"0","bgAlpha":"0","useplotgradientcolor":"0","showplotborder":"0"},"data":[{"label":"OK","value":"281"},{"label":"OK GUDANG","value":"26"},{"label":"OK MUTASI","value":"8"},{"label":"PEMINJAMAN","value":"2"},{"label":"RUSAK GUDANG","value":"0"},{"label":"RUSAK SERVICE","value":"11"},{"label":"TERJUAL","value":"0"}]}
这是我的控制器:
app.controller("GraphCtrl",function(GlobalFactory,$scope){
$scope.myDataSource = '';
$scope.getData = function(){
GlobalFactory.typeahead(restUrl('assethw_status')).then(function(d){
$scope.myDataSource = d;
console.log(d);
});
}
// if i use this the chart work normally
// this json object is same as than output from URL
$scope.myDataSource = {"chart":{"caption":"Asset Hardware by Status","numberPrefix":"","theme":"fint","showBorder":"0","borderAlpha":"0","bgAlpha":"0","useplotgradientcolor":"0","showplotborder":"0"},"data":[{"label":"OK","value":"281"},{"label":"OK GUDANG","value":"26"},{"label":"OK MUTASI","value":"8"},{"label":"PEMINJAMAN","value":"2"},{"label":"RUSAK GUDANG","value":"0"},{"label":"RUSAK SERVICE","value":"11"},{"label":"TERJUAL","value":"0"}]};
// but if i use from json url the chart show no data to display
// may i miss something?
$scope.getData();
$scope.refresh = function(){
$scope.getData();
}
});
我的问题是,
如果我使用本地 json 数据,图表可以正常工作,但如果我使用 json 形式 URL,图表显示没有数据显示。我可以错过什么吗?
提前致谢,
伊维贾亚
您应该访问响应的数据属性,将其更改为
GlobalFactory.typeahead(restUrl('assethw_status')).then(function(d){
$scope.myDataSource = d.data;
});
我使用 angular js 的融合图表。我的数据来自 json url 和 http angular(我的工厂),这里是我的 json 对象:
{"chart":{"caption":"Asset Hardware by Status","numberPrefix":"","dataFormat":"json","theme":"fint","showBorder":"0","borderAlpha":"0","bgAlpha":"0","useplotgradientcolor":"0","showplotborder":"0"},"data":[{"label":"OK","value":"281"},{"label":"OK GUDANG","value":"26"},{"label":"OK MUTASI","value":"8"},{"label":"PEMINJAMAN","value":"2"},{"label":"RUSAK GUDANG","value":"0"},{"label":"RUSAK SERVICE","value":"11"},{"label":"TERJUAL","value":"0"}]}
这是我的控制器:
app.controller("GraphCtrl",function(GlobalFactory,$scope){
$scope.myDataSource = '';
$scope.getData = function(){
GlobalFactory.typeahead(restUrl('assethw_status')).then(function(d){
$scope.myDataSource = d;
console.log(d);
});
}
// if i use this the chart work normally
// this json object is same as than output from URL
$scope.myDataSource = {"chart":{"caption":"Asset Hardware by Status","numberPrefix":"","theme":"fint","showBorder":"0","borderAlpha":"0","bgAlpha":"0","useplotgradientcolor":"0","showplotborder":"0"},"data":[{"label":"OK","value":"281"},{"label":"OK GUDANG","value":"26"},{"label":"OK MUTASI","value":"8"},{"label":"PEMINJAMAN","value":"2"},{"label":"RUSAK GUDANG","value":"0"},{"label":"RUSAK SERVICE","value":"11"},{"label":"TERJUAL","value":"0"}]};
// but if i use from json url the chart show no data to display
// may i miss something?
$scope.getData();
$scope.refresh = function(){
$scope.getData();
}
});
我的问题是, 如果我使用本地 json 数据,图表可以正常工作,但如果我使用 json 形式 URL,图表显示没有数据显示。我可以错过什么吗?
提前致谢, 伊维贾亚
您应该访问响应的数据属性,将其更改为
GlobalFactory.typeahead(restUrl('assethw_status')).then(function(d){
$scope.myDataSource = d.data;
});