0

I'm trying to create a tested graph mimicking this chart from this documentation.

In my JSFiddle (https://jsfiddle.net/bheng/2pcmubwq/)

I tried adding all the links needed in the resources :

HTML

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

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]
  ];
});

Result

I see no errors in the console, but this white screen.

What did I do wrong to make my graph didn't render?

2
  • 1
    In the future use a linter or IDE that can spot errors for you. The HTML is badly formed. Commented Mar 4, 2021 at 21:23
  • Ok. Will do. I was playing with js fiddle forgot to test it locally. I would have caught that. Commented Mar 4, 2021 at 21:26

1 Answer 1

2

Every angularJs app have to be mounted in the document using those directives: ng-app ng-controller
Your fiddle fixed: https://jsfiddle.net/nmwypgdq/9/

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

$scope object passed by controller callback is available in your template. You can reference its properties and methods in the template. Thus chart-data="data" binds HTML element property chart-data with $scope.data defined in the controller callback. chart-labels is bound with $scope.labels and so on...

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.