简体   繁体   中英

Error in implementing chart.js in AngularJS

I followed steps given in the link Angular chart JS But unable to draw a graph(Bar graph) from the data.

My dashboard.html is

<div class="md-padding" flex layout-sm="column" >
<md-card class="text-center">
<md-card-content>
<canvas id="bar" class="chart chart-bar" ng-controller="DashboardCtrl"chart-data="data" chart-labels="labels" chart-series="series">
</canvas>
</md-card-content>
</md-card>
</div>

My dashboardctrl.js is

(function () {
'use strict';

angular.module("home", ["chart.js"])
.config(['ChartJsProvider', function (ChartJsProvider) {
 ChartJsProvider.setOptions({
  chartColors: ['#FF5252', '#FF8A80'],
  responsive: false
  });
// Configure all line charts
ChartJsProvider.setOptions('line', {
  datasetFill: false
 });
}])
.controller("DashboardCtrl", ['$scope', function ($scope) {

$scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
$scope.series = ['Series A', 'Series B'];

$scope.data = [
  [65, 59, 80, 81, 56, 55, 40],
  [28, 48, 40, 19, 86, 27, 90]
];
console.log("done");
}]);
})();

I am getting error

Multiple directives [ngController, chartBar] asking for new/isolated scope on:`

Thanks for your help in advance. `

<div class="md-padding" flex layout-sm="column" ng-controller="DashboardCtrl">
   <md-card class="text-center">
      <md-card-content>
         <canvas id="bar" class="chart chart-bar" chart-data="data" chart-labels="labels" chart-series="series"></canvas>
      </md-card-content>
   </md-card>
</div>

You need to move ng-controller to another element. Both the controller and the chartBar directive try to register a new isolated scope as the error message says

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM