AngularJS饼图未显示

时间:2018-02-11 14:58:17

标签: javascript angularjs charts

我有以下Index.html:

<!DOCTYPE>
<html>
<head>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.2/Chart.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-charts/0.2.7/angular-charts.min.js"></script>
    <script src="chart-module.js"></script>
</head>
<body>
    <canvas id="pie" class="chart chart-pie" chart-data="data" chart-labels="labels" chart-options="options"></canvas>
</body>
</html>

以下chart-module.js:

angular.module("app", ["chart.js"]).controller("PieCtrl", function ($scope) 
{
   $scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales"];
   $scope.data = [300, 500, 100];
});

当我在chrome上运行Index.html时,不会显示饼图。 我试过并寻找解决方案,但没有一个能为我工作。

我在chrome控制台上没有错误。 我已经关注了this教程。

1 个答案:

答案 0 :(得分:1)

您需要引用chart.js和angular-chart.js

的匹配版本
 <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
 <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script>

<强> DEMO

&#13;
&#13;
angular.module("app", ["chart.js"])
.controller("PieCtrl", function ($scope){
   $scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales"];
   $scope.data = [300, 500, 100];
});
&#13;
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8" />
  <title>Multi Slot Transclude</title>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.3.0/Chart.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-chart.js/1.0.3/angular-chart.min.js"></script>
</head>
<body ng-app="app" ng-controller="PieCtrl">
   <canvas id="pie" class="chart chart-pie" chart-data="data" chart-labels="labels" chart-options="options"></canvas>
</body>
</html>
&#13;
&#13;
&#13;