Angularchart.js显示错误图表未定义
Angular chart.js showing error chart is not defined
我是 angular js 的新手。当我尝试执行以下代码时。它在控制台中显示一些错误。 ReferenceError: Chart is not defined 。我无法理解这些错误。所以有人请帮助我。如果问题不正确,请更正问题
我的Html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>school</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="stylesheet" href="fonts/text-font/css/font_icon.css" type="text/css"/>
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<!-- angular -->
<script type="text/javascript" src="js/angular/angular.min.js"></script>
<!-- angular chart -->
<link rel="stylesheet" href="js/angular/angular-chart.css" type="text/css"/>
<script type="text/javascript" src="js/angular/angular-chart.min.js"></script><br />
<script type="text/javascript" src="js/angular/angular.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="LineCtrl">
<canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels"
chart-legend="true" chart-series="series" chart-click="onClick"></canvas>
</div>
</body >
</html>
我的 angular.js :
angular.module("app", ["chart.js"])
// Optional configuration
.config(['ChartJsProvider', function (ChartJsProvider) {
// Configure all charts
ChartJsProvider.setOptions({
colours: ['#FF5252', '#FF8A80'],
responsive: false
});
// Configure all line charts
ChartJsProvider.setOptions('Line', {
datasetFill: false
});
}])
.controller("LineCtrl", ['$scope', '$timeout', function ($scope, $timeout) {
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
// Simulate async data update
$timeout(function () {
$scope.data = [
[28, 48, 40, 19, 86, 27, 90],
[65, 59, 80, 81, 56, 55, 40]
];
}, 3000);
}]);
我把我在评论中提到的更正,ng-app 和 ng-directives 丢失了。
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>school</title>
<link rel="stylesheet" href=
"http://cdn.rawgit.com/jtblin/angular-chart.js/master/dist/angular-chart.css" type=
"text/css" />
<script src="http://cdn.rawgit.com/nnnick/Chart.js/master/Chart.min.js" type=
"text/javascript">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"
type="text/javascript">
</script>
<script src=
"http://cdn.rawgit.com/jtblin/angular-chart.js/master/dist/angular-chart.js"
type="text/javascript">
</script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="LineCtrl">
<canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels"
chart-legend="true" chart-series="series" chart-click="onClick"></canvas>
</div>
</body>
</html>
script.js
angular.module("app", ["chart.js"]) // here i couldn't understand about chart.js fil
// Optional configuration
.config(['ChartJsProvider', function (ChartJsProvider) {
// Configure all charts
ChartJsProvider.setOptions({
colours: ['#FF5252', '#FF8A80'],
responsive: false
});
// Configure all line charts
ChartJsProvider.setOptions('Line', {
datasetFill: false
});
}])
.controller("LineCtrl", ['$scope', '$timeout', function ($scope, $timeout) {
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
// Simulate async data update
$timeout(function () {
$scope.data = [
[28, 48, 40, 19, 86, 27, 90],
[65, 59, 80, 81, 56, 55, 40]
];
}, 3000);
}]);
我为它做了一个jsbin。
您需要添加 chart.js 库的引用才能使您的图表正常工作。由于 angular-chart.js 内部使用 chart.js
库的 Chart
对象。
在遵循 Angular Chart 官方文档 (http://jtblin.github.io/angular-chart.js/) 之后,我遇到了类似的问题(同样的错误)。在我的例子中,唯一缺少(并且没有在那里提到)的是 "index.html".
中对 "Chart,js" 的引用
<script src="bower_components/Chart.js/Chart.min.js"></script>
这可能是 chart.min.js 和 angular-chart.min.js files.In 的顺序问题,事实上 angular-chart.min.js
需要 chart.min.js
依赖。 angular-chart.min.js
检查 chart.min.js,如果 chart.min.js
放在后面,这会产生错误。
<script src="/lib/chart.js/dist/Chart.min.js"></script>
<script src="/lib/angular-chart.js/dist/angular-chart.min.js"></script>
这对我有用:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.11/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="http://cdn.jsdelivr.net/angular.chartjs/latest/angular-chart.min.js"></script>
我是 angular js 的新手。当我尝试执行以下代码时。它在控制台中显示一些错误。 ReferenceError: Chart is not defined 。我无法理解这些错误。所以有人请帮助我。如果问题不正确,请更正问题
我的Html代码:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>school</title>
<link rel="stylesheet" href="style.css" type="text/css"/>
<link rel="stylesheet" href="fonts/text-font/css/font_icon.css" type="text/css"/>
<meta name="viewport" content="width=device-width; initial-scale=1.0" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<!-- angular -->
<script type="text/javascript" src="js/angular/angular.min.js"></script>
<!-- angular chart -->
<link rel="stylesheet" href="js/angular/angular-chart.css" type="text/css"/>
<script type="text/javascript" src="js/angular/angular-chart.min.js"></script><br />
<script type="text/javascript" src="js/angular/angular.js"></script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="LineCtrl">
<canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels"
chart-legend="true" chart-series="series" chart-click="onClick"></canvas>
</div>
</body >
</html>
我的 angular.js :
angular.module("app", ["chart.js"])
// Optional configuration
.config(['ChartJsProvider', function (ChartJsProvider) {
// Configure all charts
ChartJsProvider.setOptions({
colours: ['#FF5252', '#FF8A80'],
responsive: false
});
// Configure all line charts
ChartJsProvider.setOptions('Line', {
datasetFill: false
});
}])
.controller("LineCtrl", ['$scope', '$timeout', function ($scope, $timeout) {
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
// Simulate async data update
$timeout(function () {
$scope.data = [
[28, 48, 40, 19, 86, 27, 90],
[65, 59, 80, 81, 56, 55, 40]
];
}, 3000);
}]);
我把我在评论中提到的更正,ng-app 和 ng-directives 丢失了。
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>school</title>
<link rel="stylesheet" href=
"http://cdn.rawgit.com/jtblin/angular-chart.js/master/dist/angular-chart.css" type=
"text/css" />
<script src="http://cdn.rawgit.com/nnnick/Chart.js/master/Chart.min.js" type=
"text/javascript">
</script>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.9/angular.min.js"
type="text/javascript">
</script>
<script src=
"http://cdn.rawgit.com/jtblin/angular-chart.js/master/dist/angular-chart.js"
type="text/javascript">
</script>
<script type="text/javascript" src="js/script.js"></script>
</head>
<body ng-app="app">
<div ng-controller="LineCtrl">
<canvas id="line" class="chart chart-line" chart-data="data" chart-labels="labels"
chart-legend="true" chart-series="series" chart-click="onClick"></canvas>
</div>
</body>
</html>
script.js
angular.module("app", ["chart.js"]) // here i couldn't understand about chart.js fil
// Optional configuration
.config(['ChartJsProvider', function (ChartJsProvider) {
// Configure all charts
ChartJsProvider.setOptions({
colours: ['#FF5252', '#FF8A80'],
responsive: false
});
// Configure all line charts
ChartJsProvider.setOptions('Line', {
datasetFill: false
});
}])
.controller("LineCtrl", ['$scope', '$timeout', function ($scope, $timeout) {
$scope.labels = ["January", "February", "March", "April", "May", "June", "July"];
$scope.series = ['Series A', 'Series B'];
$scope.data = [
[65, 59, 80, 81, 56, 55, 40],
[28, 48, 40, 19, 86, 27, 90]
];
$scope.onClick = function (points, evt) {
console.log(points, evt);
};
// Simulate async data update
$timeout(function () {
$scope.data = [
[28, 48, 40, 19, 86, 27, 90],
[65, 59, 80, 81, 56, 55, 40]
];
}, 3000);
}]);
我为它做了一个jsbin。
您需要添加 chart.js 库的引用才能使您的图表正常工作。由于 angular-chart.js 内部使用 chart.js
库的 Chart
对象。
在遵循 Angular Chart 官方文档 (http://jtblin.github.io/angular-chart.js/) 之后,我遇到了类似的问题(同样的错误)。在我的例子中,唯一缺少(并且没有在那里提到)的是 "index.html".
中对 "Chart,js" 的引用<script src="bower_components/Chart.js/Chart.min.js"></script>
这可能是 chart.min.js 和 angular-chart.min.js files.In 的顺序问题,事实上 angular-chart.min.js
需要 chart.min.js
依赖。 angular-chart.min.js
检查 chart.min.js,如果 chart.min.js
放在后面,这会产生错误。
<script src="/lib/chart.js/dist/Chart.min.js"></script>
<script src="/lib/angular-chart.js/dist/angular-chart.min.js"></script>
这对我有用:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.11/angular.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.6.0/Chart.min.js"></script>
<script src="http://cdn.jsdelivr.net/angular.chartjs/latest/angular-chart.min.js"></script>