在数据点ChartJS中显示JsonResult

Displaying JsonResult inside data point ChartJS

本文关键字:显示 JsonResult ChartJS 数据      更新时间:2023-09-26

我使用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结果?

您必须像这样在数据数组中获取结果:

$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]
...