Chartjs-Angular-Chart.js it doesn't display the chart

3👍

It looks like angular-chart.js doesn’t support version 2 of Chart.js. Below is a snippet, that shows a working chart. It includes v1.1.1 of chart.js

angular.module("app", ["chart.js"]).controller("BarCtrl", 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]
  ];
});
<!DOCTYPE html>
<html>

<head>
  <script data-require="angularjs@1.5.3" data-semver="1.5.3" src="http://ajax.googleapis.com/ajax/libs/angularjs/1.5.3/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.1.1/Chart.min.js"></script>
  <script src="http://jtblin.github.io/angular-chart.js/dist/angular-chart.js"></script>
  <link rel="stylesheet" href="https://raw.githubusercontent.com/jtblin/angular-chart.js/master/dist/angular-chart.min.css" />
  <script src="app.js"></script>
</head>

<body ng-app="app">
  <div ng-controller="BarCtrl">
    <canvas id="bar" class="chart chart-bar" chart-data="data" chart-labels="labels" chart-series="series"></canvas>
  </div>
</body>

</html>

0👍

Your data binding is wrong

<canvas id="bar" class="chart chart-bar" data="chart-data" labels="chart-labels" ></canvas>

You have no variable chart-data nor chart-labels in your controller. You named them differently.

In fact, the attributes are in reverse order. Should be chart-data=”data” chart-labels=”labels”

Example from http://jtblin.github.io/angular-chart.js/

<canvas id="bar" class="chart chart-bar" chart-data="data" chart-labels="labels" chart-series="series"></canvas>

0👍

In html data=”chart-data” would be chart-data=”data”

0👍

I was getting this error while trying your code:

(intermediate value)[e] is not a function angular chart

It seems there is a version mismatch, tried the same with my own project got the same error.
Please take V1.1.1 of Chart.js, as already answered by @dustin.

Check this fiddle.

Leave a comment