javascript - 如何使用 Angular 图表?

标签 javascript angularjs charts angular-chart

我曾尝试使用 Angular 图表。其文档在 http://jtblin.github.io/angular-chart.js/

我已经集成了 angular-chart.js、chart.js 和 angular-chart.css。我还在 Angular 模块中集成了“chart.js”。但是我发现了一个错误。 错误是未定义图表。但是不明白为什么会出现这个问题。

我的代码:

angular.module('mean.system',['ui.bootstrap','chart.js']);

在 Controller 中:

  $scope.labels = ['2006', '2007', '2008', '2009', '2010', '2011', '2012'];
  $scope.series = ['Series A', 'Series B'];

  $scope.data = [
    [65, 59, 80, 81, 56, 55, 40],
    [28, 48, 40, 19, 86, 27, 90]
  ];

HTML:

<link href="css/angular-chart.css" rel="stylesheet">
<script type="text/javascript" src="/js/angular-chart.js"></script>
<script type="text/javascript" src="/js/Chart.js"></script>


<canvas id="bar" class="chart chart-bar" data="data"
          labels="labels"></canvas>

浏览器控制台错误:

ncaught ReferenceError: Chart is not definedChart.defaults.global.responsive @ angular-chart.js:11(anonymous function) @ angular-chart.js:13
angular.js:78 Uncaught Error: [$injector:modulerr] Failed to instantiate module mean due to:
Error: [$injector:modulerr] Failed to instantiate module chart.js due to:
Error: [$injector:nomod] Module 'chart.js' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.
http://errors.angularjs.org/1.2.6/$injector/nomod?p0=chart.js
    at http://localhost/lib/angular/angular.js:78:12
    at http://localhost/lib/angular/angular.js:1526:17
    at ensure (http://localhost/lib/angular/angular.js:1451:38)
    at module (http://localhost/lib/angular/angular.js:1524:14)
    at http://localhost/lib/angular/angular.js:3614:22
    at Array.forEach (native)
    at forEach (http://localhost/lib/angular/angular.js:302:11)
    at loadModules (http://localhost/lib/angular/angular.js:3608:5)
    at http://localhost/lib/angular/angular.js:3615:40
    at Array.forEach (native)
http://errors.angularjs.org/1.2.6/$injector/modulerr?p0=chart.js&p1=Error%3…ngular%2Fangular.js%3A3615%3A40%0A%20%20%20%20at%20Array.forEach%20(native)
    at http://localhost/lib/angular/angular.js:78:12
    at http://localhost/lib/angular/angular.js:3642:15
    at Array.forEach (native)
    at forEach (http://localhost/lib/angular/angular.js:302:11)
    at loadModules (http://localhost/lib/angular/angular.js:3608:5)
    at http://localhost/lib/angular/angular.js:3615:40
    at Array.forEach (native)
    at forEach (http://localhost/lib/angular/angular.js:302:11)
    at loadModules (http://localhost/lib/angular/angular.js:3608:5)
    at createInjector (http://localhost/lib/angular/angular.js:3548:11)
http://errors.angularjs.org/1.2.6/$injector/modulerr?p0=mean&p1=Error%3A%20…njector%20(http%3A%2F%2Flocalhost%2Flib%2Fangular%2Fangular.js%3A3548%3A11)

最佳答案

您必须将脚本添加到 chartjs 文件

<script src="bower_components/Chart.js/Chart.min.js"></script>

关于javascript - 如何使用 Angular 图表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31200378/

相关文章:

javascript - 关于 ![CDATA[,它是什么?

javascript - 在 Google Chart 中显示/隐藏线条/数据

javascript - 使用 Angular JS 中的拖放 ui-tree 时表格宽度正在缩小

angularjs - 使用基于 token 的身份验证时处理数据的最佳方法是什么

angularjs - Angular2 和 TSD 出现 "Duplicate identifier"错误

javascript - 请推荐一种或多种最佳图表组件,Flash或javascript

ios - 如何使用 Shinobi iOS SDK 打开/关闭图表系列?

javascript - 如何清除内容 - Bootstrap Modal

javascript - 访问环境变量时出现意外标记

Javascript 代码没有捕获空值