簡體   English   中英

在數據點ChartJS內部顯示JsonResult

[英]Displaying JsonResult inside data point ChartJS

我將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]
...

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM