TypeError: Cannot read property 'datasets' of undefined - Angular Chart
TypeError: Cannot read property 'datasets' of undefined - Angular Chart
我正在尝试使用 angular 图表显示图表。但是我收到以下错误:
TypeError: 无法读取未定义的 属性 'datasets'
在 Object.i.Type.extend.initialize (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:27506)
在 Object.e.Type (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:9713)
在 Object.s (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:12974)
在 e.(匿名函数)[作为 Bar] (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:13316)
我的代码:
app.controller('graphController', ['$scope', '$kinvey','$location', function($scope, $kinvey, $location) {
$scope.popula = function(){
var query = new $kinvey.Query();
query.equalTo('idColetor', 659238569);
query.descending('tsmilliseconds').limit(7);
var promise = $kinvey.DataStore.find('dataBase', query);
promise.then(function(response) {
arrayVelocidade = [];
for(var j = response.length - 1; j >= 0 ; j--) {
arrayVelocidade.push(response[j].veloc);
}
drawLineChart(arrayVelocidade);
});
};
function drawLineChart(arrayVelocidade){
$scope.lineChartData = {
labels: ["30", "25", "20", "15", "10", "05", "0"],
datasets: [
{
label: "Velocidade",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: arrayVelocidade
}
]
};
$scope.activeData = $scope.lineChartData;
}
}
]);
在我调用的索引页中:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
<script src="http://da189i1jfloii.cloudfront.net/js/kinvey-angular-1.5.1.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js"></script>
<script type="text/javascript" src="dist/angular-chartjs.min.js"></script>
<script src="js/jquery.js"></script>
任何信息都会有所帮助。谢谢!
angular-chart 期望输入数据采用特定格式(与 Chart.js 不完全相同)。尝试格式化您的输入数据,使其看起来类似于 http://jtblin.github.io/angular-chart.js/
中的示例
angular.module("app", ["chart.js"]).controller("LineCtrl", function ($scope) {
$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]
];
});
请注意,data
只是一个数组数组,而不是像 Chart.js 中那样的对象,labels
是一个单独的数组。
我正在尝试使用 angular 图表显示图表。但是我收到以下错误:
TypeError: 无法读取未定义的 属性 'datasets' 在 Object.i.Type.extend.initialize (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:27506) 在 Object.e.Type (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:9713) 在 Object.s (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:12974) 在 e.(匿名函数)[作为 Bar] (http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:13316)
我的代码:
app.controller('graphController', ['$scope', '$kinvey','$location', function($scope, $kinvey, $location) {
$scope.popula = function(){
var query = new $kinvey.Query();
query.equalTo('idColetor', 659238569);
query.descending('tsmilliseconds').limit(7);
var promise = $kinvey.DataStore.find('dataBase', query);
promise.then(function(response) {
arrayVelocidade = [];
for(var j = response.length - 1; j >= 0 ; j--) {
arrayVelocidade.push(response[j].veloc);
}
drawLineChart(arrayVelocidade);
});
};
function drawLineChart(arrayVelocidade){
$scope.lineChartData = {
labels: ["30", "25", "20", "15", "10", "05", "0"],
datasets: [
{
label: "Velocidade",
fillColor: "rgba(220,220,220,0.2)",
strokeColor: "rgba(220,220,220,1)",
pointColor: "rgba(220,220,220,1)",
pointStrokeColor: "#fff",
pointHighlightFill: "#fff",
pointHighlightStroke: "rgba(220,220,220,1)",
data: arrayVelocidade
}
]
};
$scope.activeData = $scope.lineChartData;
}
}
]);
在我调用的索引页中:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular-route.js"></script>
<script src="http://da189i1jfloii.cloudfront.net/js/kinvey-angular-1.5.1.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js"></script>
<script type="text/javascript" src="dist/angular-chartjs.min.js"></script>
<script src="js/jquery.js"></script>
任何信息都会有所帮助。谢谢!
angular-chart 期望输入数据采用特定格式(与 Chart.js 不完全相同)。尝试格式化您的输入数据,使其看起来类似于 http://jtblin.github.io/angular-chart.js/
中的示例angular.module("app", ["chart.js"]).controller("LineCtrl", function ($scope) {
$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]
];
});
请注意,data
只是一个数组数组,而不是像 Chart.js 中那样的对象,labels
是一个单独的数组。