gpt4 book ai didi

javascript - 显示多个图表 angular.js Chart.js

转载 作者:行者123 更新时间:2023-12-03 08:22:24 25 4
gpt4 key购买 nike

我想在一个页面中显示多个图表,但只显示一个(第一个“手数”)。

在 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>

脚本:

<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>

如何同时显示两者?

最佳答案

根据 AngularJS 网站,每个 HTML 文档只能自动引导一个 AngularJS 应用程序。 Ng-app API document .

为了解决您的问题,您只允许一个 html 文档拥有一个 ng-app。在这种情况下,您可以在 body 标记或 html 标记中声明 ng-app = "app"。然后将 Controller 分配给不同的 div 标签。

超文本标记语言
<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];
});

关于javascript - 显示多个图表 angular.js Chart.js,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33696173/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com