0

I want to display multiple charts in a single page, but only one is display (the first, "lots").

On the HTML :

<div ng-app="app" ng-controller="lots">
    <h3>Comparatif des lots en volume</h3>
        <canvas id="doughnut" class="chart chart-doughnut" chart-data="data" chart-labels="labels" height="100px" chart-legend="legend"></canvas>           
</div>
<div ng-app="app2" ng-controller="repartition">
    <h3>Répartition des différents types</h3>
        <canvas id="doughnut2" class="chart chart-doughnut" chart-data="data" chart-labels="labels" height="100px" chart-legend="legend"></canvas> 
</div>

The script :

<script>
    angular.module("app", ["chart.js"]).controller("lots", function ($scope) {
      $scope.labels = ["Non lotis", "Lot 1", "Lot 2"];
      $scope.data = [90, 5, 5];
    });
    angular.module("app2", ["chart.js"]).controller("repartition", function ($scope) {
      $scope.labels = ["JCL", "Appli", "Copy", "Mapset", "PGM"];
      $scope.data = [80, 2, 3, 0.5, 10];
    });
</script>

How can I display both ?

1 Answer 1

1

According to AngularJS website, Only one AngularJS application can be auto-bootstrapped per HTML document. Ng-app API document.

To fixed your issue, you only allow to have one ng-app for one html document. In this case, either you declare ng-app = "app" in body tag or in html tag. And then assign controller to different div tag.

HTML
<body ng-app="app">
  <div ng-controller="lots">
    <h3>Comparatif des lots en volume</h3>
    <canvas id="doughnut" class="chart chart-doughnut"
            chart-data="data" chart-labels="labels" height="100px" 
            chart-legend="legend">
    </canvas>           
  </div>
  <div ng-controller="repartition">
    <h3>Répartition des différents types</h3>
    <canvas id="doughnut2" class="chart chart-doughnut" 
            chart-data="data" chart-labels="labels" height="100px" 
            chart-legend="legend">
    </canvas> 
  </div>
</body>
JS
angular.module("app", ["chart.js"])
       .controller("lots", function ($scope) {
           $scope.labels = ["Non lotis", "Lot 1", "Lot 2"];
           $scope.data = [90, 5, 5];
        })
       .controller("repartition", function ($scope) {
           $scope.labels = ["JCL", "Appli", "Copy", "Mapset", "PGM"];
           $scope.data = [80, 2, 3, 0.5, 10];
        });
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.