I am using asp .net mvc web app with AngularJS and chart.js to create chart.
Taking the bar chart example: http://jtblin.github.io/angular-chart.js/
I have a list of data from MVC controller, and I would like to pass this data to angular controller.
/Displaycharts/Columnchart is link to get datalist from c# controller to angular controller.
May I know the $scope.labels and $scope.data are assigned correctly?
Appreciate if you could help to modify the sample and SQL script which can be downloaded from here.
Thanks!
Code:
angular
.module('MyApp', 'Chart.js', 'DisplaychartsngController.js')
.controller('DisplaychartsngController', function ($scope, MarketService) {
$scope.Markets = null;
MarketService.GetMarketList().then(function (d) {
$scope.Markets = d.data; //Success callback
$scope.labels = $scope.Markets.PlanName;
$scope.series= ['PaymentAmount'];
$scope.data = $scope.Markets.PaymentAmount;
}, function (error) {
alert('Error!'); // Failed Callback
});
})
$scope.labelsand$scope.data?PlanNameseems to be a sting andPaymentAmounta number, right?$scope.datatakes a series of data such as[1,2,3,4]. In case of a bar chart you assign either a single array or a set of arrays.