Chartjs-Angular chartjs directive

0👍

Found the way to do it.

angular.module('chartjs-directive', []).
 directive('divChart', function () {
var baseWidth = 600;
var baseHeight = 400;

return {
  restrict: 'A',
  template: '<canvas></canvas>',
  scope: {
    divChart:"=",
    chartObject: "=value"
  },
------
------
});

In HTML:

 <div id="myColChart" div-Chart value="myChart"></div>

I know this is basic stuff, but this is the first time I’m working with angular.

1👍

For this you need to change directive name and its restrict value.

Your chart directive should look like this:

 app.directive('chartUse', function () {

    return {
       restrict: "A",
       .....
    }
 });

Leave a comment