我正在AngularJS文件中构建一个dx图表。我想在我的ng-controller中使用$ http.get。这是AngularJS文件。但是,当我尝试使用$ http.get时,我仍然显示图表,但没有传入数据。如果我在dataSource中删除$ http参数和$ http.get,我可以使用Json显示我的数据格式从我的URL传入。
AngularJS文件
var app = angular.module('customCharts', ['dx']);
function ChartController($scope, $http) {
$scope.productSettings = {
dataSource: $http.get("http://localhost:53640/Home/PostChart"),
title: 'Displays Product Costs for items in our Database',
series: {
argumentField: "Name",
valueField: "Cost",
type: "bar",
color: '#008B8B'
},
commonAxisSettings: {
visible: true,
color: 'black',
width: 2
},
argumentAxis: {
title: 'Items in Product Store Database'
},
valueAxis: {
title: 'Dollor Amount',
valueFormat: 'currency'
}
}
}
答案 0 :(得分:0)
希望您对controller
声明有疑问:
您可以修改以下代码:
var app = angular.module('customCharts', ['dx']);
app.controller('ChartController', ['$scope', '$http', function($scope, $http) {
$scope.productSettings = {
dataSource: $http.get("http://localhost:53640/Home/PostChart"),
title: 'Displays Product Costs for items in our Database',
series: {
argumentField: "Name",
valueField: "Cost",
type: "bar",
color: '#008B8B'
},
commonAxisSettings: {
visible: true,
color: 'black',
width: 2
},
argumentAxis: {
title: 'Items in Product Store Database'
},
valueAxis: {
title: 'Dollor Amount',
valueFormat: 'currency'
}
}
}]);
答案 1 :(得分:0)
试试这个
function ChartController($scope, $http) {
$http.get("http://localhost:53640/Home/PostChart").success(function (data) {
$scope.productSettings = {
dataSource: data,
title: 'Displays Product Costs for items in our Database',
series: {
argumentField: "Name",
valueField: "Cost",
type: "bar",
color: '#008B8B'
},
commonAxisSettings: {
visible: true,
color: 'black',
width: 2
},
argumentAxis: {
title: 'Items in Product Store Database'
},
valueAxis: {
title: 'Dollor Amount',
valueFormat: 'currency'
}
};
});
}