Angular Chart js饼图不起作用

时间:2016-05-31 22:49:34

标签: javascript angularjs charts pie-chart angular-chart

我安装了所有依赖项,我的代码似乎是正确的,仍然无法指出为什么代码根本没有呈现。

提前致谢。

<!DOCTYPE html> 
<html>
<head>
<link rel="stylesheet" href="bower_components/angular-chart.js/dist/angular-chart.css"> 
<script src="bower_components/angular-chart.js/dist/angular-chart.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head> 
<body>
<div ng-app="app" ng-controller="PolarAreaCtrl">
<canvas id="polar-area" class="chart chart-polar-area"
  chart-data="data" chart-labels="labels">
</canvas>
</div> 
<script>
angular.module("app", ["chart.js"]).controller("PolarAreaCtrl", function ($scope) {
  $scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales", "Tele Sales", "Corporate Sales"];
  $scope.data = [300, 500, 100, 40, 120];
});
</script>
</body>
</html>  

1 个答案:

答案 0 :(得分:0)

根据here - angular-chart.js不支持Chart.js的第2版。下面是一个片段,显示了一个工作图表。它包括chart.js的v1.1.1

我使用了以下内容及其工作原理:

<!DOCTYPE html>
<html>
<head>
    <script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.1.1/Chart.min.js"></script>
    <script src="http://jtblin.github.io/angular-chart.js/dist/angular-chart.js"></script>
    <link rel="stylesheet" href="https://raw.githubusercontent.com/jtblin/angular-chart.js/master/dist/angular-chart.min.css" />
</head>
<body>
<div ng-app="app" ng-controller="PolarAreaCtrl">
    <canvas id="polar-area" class="chart chart-polar-area"
            chart-data="data" chart-labels="labels">
    </canvas>
</div>
<script>
    angular.module("app", ["chart.js"]).controller("PolarAreaCtrl", function ($scope) {
        $scope.labels = ["Download Sales", "In-Store Sales", "Mail-Order Sales", "Tele Sales", "Corporate Sales"];
        $scope.data = [300, 500, 100, 40, 120];
    });
</script>
</body>
</html>