Javascript 在数据点ChartJS内显示JsonResult
我将MVC5与AngularJS一起使用,我被如何插入我的ChartJS控制器所困扰 .CS控制器Javascript 在数据点ChartJS内显示JsonResult,javascript,angularjs,model-view-controller,jsonresult,Javascript,Angularjs,Model View Controller,Jsonresult,我将MVC5与AngularJS一起使用,我被如何插入我的ChartJS控制器所困扰 .CS控制器 public JsonResult GetTodaySoFar() { TodaySoFarModel todaysofarModel = new TodaySoFarModel(); todaysofarModel.TodaySoFar.Add(new TodaySoFarItemModel { TodaySoFarData = "[22,44,55]
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结果 您必须在如下数据数组中获取结果:
$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]
...
您必须在如下数据数组中获取结果:
$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]
...
@user2894034我已经编辑了我的答案。。你能测试一下这个例子吗?数据仍然没有绘制这3个点。是否需要从字符串转换为int?@user2894034我使用的是chart.js的角度模块,它与上面的示例一起工作。如果我在数据中插入值而不是[$scope.todaysofar],它会工作fine@user2894034我已经编辑了我的答案。。你能测试一下这个例子吗?数据仍然没有绘制这3个点。是否需要从字符串转换为int?@user2894034我使用的是chart.js的角度模块,它可以与上面的示例一起使用。如果我在数据中插入值而不是[$scope.todaysofar],则效果很好