1

我正在关注 Chart.js 示例。但是,当我尝试渲染该示例时,出现以下错误:

未捕获的类型错误:无法读取未定义的属性“绘制”

这是我正在关注的示例。我已经相应地做了所有事情,但我不知道为什么会导致这个问题。 http://carlcraig.github.io/tc-angular-chartjs/doughnut/

下面是我对该示例的实现。我的模块

angular.module('main')
    .controller('AboutController', ['$scope', function ($scope) {
         $scope.data = [
      {
          value: 300,
          color: '#F7464A',
          highlight: '#FF5A5E',
          label: 'Red'
      },
      {
          value: 50,
          color: '#46BFBD',
          highlight: '#5AD3D1',
          label: 'Green'
      },
      {
          value: 100,
          color: '#FDB45C',
          highlight: '#FFC870',
          label: 'Yellow'
      }
    ];

    // Chart.js Options
    $scope.options = {

        // Sets the chart to be responsive
        responsive: true,

        //Boolean - Whether we should show a stroke on each segment
        segmentShowStroke: true,

        //String - The colour of each segment stroke
        segmentStrokeColor: '#fff',

        //Number - The width of each segment stroke
        segmentStrokeWidth: 2,

        //Number - The percentage of the chart that we cut out of the middle
        percentageInnerCutout: 50, // This is 0 for Pie charts

        //Number - Amount of animation steps
        animationSteps: 100,

        //String - Animation easing effect
        animationEasing: 'easeOutBounce',

        //Boolean - Whether we animate the rotation of the Doughnut
        animateRotate: true,

        //Boolean - Whether we animate scaling the Doughnut from the centre
        animateScale: false,

        //String - A legend template
        legendTemplate: '<ul class="tc-chart-js-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>'

    };
    }]);

这是我的html代码

<canvas tc-chartjs-doughnut chart-options="options" chart-data="data" auto-legend></canvas>

我应该补充一点,我能够渲染图表的图例。 传奇

4

3 回答 3

0

draw是一个 Chart.js 方法——你确定你已经包含了所有的依赖吗?

<script type="text/javascript" src="js/Chart.js"></script>
<script type="text/javascript" src="js/angular.js"></script>
<script type="text/javascript" src="js/tc-angular-chartjs.js"></script>

您还需要将其列为您的 app/ 的要求angular.module

angular.module( 'main', ['tc.chartjs']);
于 2015-06-08T23:27:44.027 回答
0

确保您拥有兼容的 Chart.js 版本。1.0.2 版适用于您使用 tc-angular v1.0.11 的示例

确保除了 angular、tc-angular 和 Chart.js 之外,您没有加载其他库(至少开始时)。

于 2015-06-09T10:17:46.973 回答
0

试图重现您的错误,我很快就遇到了完全相同的问题 - 但是在运行$ bower install tc-angular-chartjs并复制所有代码之后,这就是结果,它工作正常。它还包括所需的脚本和模块依赖项,如教程中所示并由 Tina 提到

<!Doctype html>
<html>
<body>
<div ng-app="main">
  <div ng-controller="AboutController">
    <canvas tc-chartjs-doughnut chart-options="options" chart-data="data" auto-legend></canvas>
  </div>
</div>
<script src="bower_components/Chart.js/Chart.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/tc-angular-chartjs/dist/tc-angular-chartjs.min.js"></script>
<script>
  angular
      .module('main', ['tc.chartjs'])
      .controller('AboutController', ['$scope', function ($scope) {
        $scope.data = [
          {
            value: 300,
            color: '#F7464A',
            highlight: '#FF5A5E',
            label: 'Red'
          },
          {
            value: 50,
            color: '#46BFBD',
            highlight: '#5AD3D1',
            label: 'Green'
          },
          {
            value: 100,
            color: '#FDB45C',
            highlight: '#FFC870',
            label: 'Yellow'
          }
        ];

        // Chart.js Options
        $scope.options = {

          // Sets the chart to be responsive
          responsive: true,

          //Boolean - Whether we should show a stroke on each segment
          segmentShowStroke: true,

          //String - The colour of each segment stroke
          segmentStrokeColor: '#fff',

          //Number - The width of each segment stroke
          segmentStrokeWidth: 2,

          //Number - The percentage of the chart that we cut out of the middle
          percentageInnerCutout: 50, // This is 0 for Pie charts

          //Number - Amount of animation steps
          animationSteps: 100,

          //String - Animation easing effect
          animationEasing: 'easeOutBounce',

          //Boolean - Whether we animate the rotation of the Doughnut
          animateRotate: true,

          //Boolean - Whether we animate scaling the Doughnut from the centre
          animateScale: false,

          //String - A legend template
          legendTemplate: '<ul class="tc-chart-js-legend"><% for (var i=0; i<segments.length; i++){%><li><span style="background-color:<%=segments[i].fillColor%>"></span><%if(segments[i].label){%><%=segments[i].label%><%}%></li><%}%></ul>'

        };
      }]);
</script>
</body>
</html>
于 2015-06-09T16:54:39.493 回答