我通過調用ajax調用將數據傳遞給圖表從API獲取數據。 我無法呈現圖表。任何人都可以建議我可能是什麼問題?Am Chart在ajax調用後不加載圖表
這是我的Ajax調用
你可以看到Ajax調用後,我試圖推到範圍變量,並嘗試添加到圖表。
參考,請找到此鏈接http://jsfiddle.net/w3vpc35o/41/
angular.module('amChartsDirectiveExample', ['amChartsDirective']).controller('amChartsController', function ($scope) {
$scope.call = function(){
$http({
method: "get",
global: false,
async: true,
url: "server/test.php
}).
success(function(data) {
/*Assume data like like [{
year: 2005,
income: 23.5,
expenses: 18.1
}, {
year: 2006,
income: 26.2,
expenses: 22.8
}, {
year: 2007,
income: 30.1,
expenses: 23.9
}, {
year: 2008,
income: 29.5,
expenses: 25.1
}, {
year: 2009,
income: 24.6,
expenses: 25
}]*/
$scope.rest = data
$scope.amChartOptions = {
data:$scope.res ,
type: "serial",
theme: 'black',
categoryField: "year",
rotate: true,
pathToImages: 'https://cdnjs.cloudflare.com/ajax/libs/amcharts/3.13.0/images/',
legend: {
enabled: true
},
chartScrollbar: {
enabled: true,
},
categoryAxis: {
gridPosition: "start",
parseDates: false
},
valueAxes: [{
position: "top",
title: "Million USD"
}],
graphs: [{
type: "column",
title: "Income",
valueField: "income",
fillAlphas: 1,
}]
}
});
}
$scope.call();
});
發佈您的代碼在這裏 – Sajeetharan
我已經更新代碼。我也使用了異步調用。但不能使用。 – user3335796