【发布时间】:2015-03-27 15:14:43
【问题描述】:
使用 $http.get 时,我不再在条形图中看到数据。如果我删除 $http.get 并只调用 url 我的数据就可以了。任何想法我做错了什么?
AngularJS
var app = angular.module('customCharts', ['dx']);
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'
}
};
});
}
HTML
<div ng-app="customCharts">
<div ng-controller="ChartController">
<div dx-chart="productSettings"></div>
</div>
</div>
JSON
[{"Name":"Learn SQL Server 2014","Cost":34.95},{"Name":"ASUS PC","Cost":499.99},{"Name":"SQL Server 2014","Cost":600.00}]
【问题讨论】:
-
data实际上是数据,还是实际上是响应,并且您想使用data.data(或将data重命名为response并执行response.data) -
.success 函数内部?
-
@Tom $http.get("localhost:53640/Home/PostChart") .success(function (response) { $scope.productSettings = { dataSource: response.data ..........仍然不工作
-
@jumpingcode 是的,那是我的。我似乎无法获得显示。我再也没有收到关于该帖子的建议,所以想再试一次。
标签: json asp.net-mvc angularjs