[英]TypeError: Cannot read property 'datasets' of undefined - Angular Chart
I am trying to show a chart using angular chart. 我正在尝试使用角度图表显示图表。 But I'm get the following error: 但是我收到以下错误:
TypeError: Cannot read property 'datasets' of undefined at Object.i.Type.extend.initialize ( http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:27506 ) at Object.e.Type ( http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:9713 ) at Object.s ( http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:12974 ) at e.(anonymous function) [as Bar] ( http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:13316 ) TypeError:无法读取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。(匿名函数)[栏]( http://cdnjs.cloudflare.com/ajax/libs/Chart.js/1.0.1-beta.2/Chart.min.js:9:13316 )
My code: 我的代码:
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;
}
}
]);
In the index page I called: 在索引页面中,我调用了:
<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>
Any information would help. 任何信息都会有所帮助。 thanks ! 谢谢 !
angular-chart expects the input data to be in a certain format (it's not exactly the same as Chart.js). angular-chart期望输入数据采用某种格式(与Chart.js不完全相同)。 Try formatting your input data to look something like the sample at http://jtblin.github.io/angular-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]
];
});
Notice that data
is just an array of arrays, not an object like in Chart.js and labels
is a separate array. 注意, data
只是一个数组数组,而不是Chart.js中的对象,而labels
是一个单独的数组。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.