我正在使用MVC 5和AngularJS,而我却陷入了如何插入我的ChartJS控制器。
.CS控制器
public JsonResult GetTodaySoFar()
{
TodaySoFarModel todaysofarModel = new TodaySoFarModel();
todaysofarModel.TodaySoFar.Add(new TodaySoFarItemModel { TodaySoFarData = "[22,44,55]" });
return Json(todaysofarModel, JsonRequestBehavior.AllowGet);
}
这是我的控制器,它正在获取数据。
$http.get('/revenue/gettodaysofar').success(function (data) {
//debugger;
$scope.todaysofar = data.TodaySoFar;
console.log($scope.todaysofar);
$scope.loading = false;
})
$scope.revenueToday = {
labels: ['00:00', '01:00', '02:00', '03:00', '04:00', '05:00'],
datasets: [
{
label: 'My Second dataset',
fillColor: 'rgba(35,183,229,0.2)',
strokeColor: 'rgba(35,183,229,1)',
pointColor: 'rgba(35,183,229,1)',
pointStrokeColor: '#fff',
pointHighlightFill: '#fff',
pointHighlightStroke: 'rgba(35,183,229,1)',
data: [] //Trying to add 22,44,55 from the JsonResult
}
]
};
如何在数据中插入Json结果?
答案 0 :(得分:0)
你必须在这样的数据数组中得到结果:
$scope.todaysofar = [];
$http.get('/revenue/gettodaysofar').success(function (data) {
//debugger;
$scope.todaysofar.push(data.TodaySoFar);
console.log($scope.todaysofar);
$scope.loading = false;
})
...
data: [$scope.todaysofar]
...