score:0

there's a few issues with the code that you've posted. the key ones that i see that will get the chart rendering happening are as follows:

first, your ng-repeat is using options, but you also have a scope variable called options, and i think they are clashing (or at the very least, not doing what you think they are doing).

changing $scope.options = {...} to $scope.chartoptions = {...}, and chart-options="options" to chart-options="chartoptions" will fix this.

second, your ng-repeat is looking for chart-data and chart-labels inside each person. you've only defined name and number, so there is no data to display.

on this, i can see that you've iterated over the person array and dropped all the information into a scope data and labels array.

that means that while you are rendering a chart per person, you're effectively rendering the same chart each time.

a full working version follows:

<link rel="stylesheet" href="http://jtblin.github.io/angular-chart.js/node_modules/bootstrap/dist/css/bootstrap.min.css">
<script src="http://jtblin.github.io/angular-chart.js/node_modules/angular/angular.min.js"></script>
<script src="http://jtblin.github.io/angular-chart.js/node_modules/chart.js/dist/chart.min.js"></script>
<script src="http://jtblin.github.io/angular-chart.js/dist/angular-chart.js"></script>


<script>
  var app = angular.module("rodoapp", ["chart.js"]);
  app.controller("chartcontroller", function ($scope, $http) {
    $scope.person = [
      {
        "name": "rodrigo",
        "number": 5,
      },
      {
        "name": "carlos",
        "number": 11,
      },
      {
        "name": "arnold",
        "number": 20,
      }
    ];


    $scope.labels = [];
    $scope.data = [];

    for (i = 0; i < $scope.person.length; i++) {
      $scope.labels.push($scope.person[i].name);
      $scope.data.push($scope.person[i].number);
    }

    $scope.chartoptions = {
      legend: {
        display: true,
      },
      title: {
        display: true,
        text: 'title'
      } 
    };

  });
</script>
<body ng-app="rodoapp" ng-controller="chartcontroller">

  <div ng-repeat="t in person">
    <div>{{t.name}} - {{t.number}}</div>
  </div>
  <hr />
  <div ng-repeat="options in person track by $index">
    <canvas ng-attr-id="{{options.name}}" class="chart chart-pie"  chart-options="chartoptions" chart-data="data" chart-labels="labels" />
  </div>
</body>

while this renders the charts, the make up of the data and why you want to repeat this is something that you'll need to think about, and possible ask another question on.


More Query from same tag