[英]Cannot read property 'map' of undefined - Google chart
I have problem with google chart. 我有谷歌图表的问题。 I get error in console: 我在控制台中收到错误:
When I refresh or click on some other link and go back to the same link it's work great. 当我刷新或单击其他链接并返回相同的链接时,它的工作效果很好。 But I get this error only when I first time load page. 但是,只有在我第一次加载页面时,才会出现此错误。
This is my code: 这是我的代码:
google.charts.load('current', {
callback: function () {
var teamNames = $scope.teams.map(team => team.team_name);
var days = $scope.teams.map(team => team.date_activity);
var avgMaxHRLastDays = $scope.teams.map(team => team.avgMaxHRLastDays);
var days = $scope.teams.map(team => team.date_activity);
var withDates = avgMaxHRLastDays.map(data => data);
var newArray = matrixTranspose(withDates);
var dataChart = newArray.map(data => [''].concat(data));
console.log("dataChart ", dataChart);
var filled = dataChart.map(data => fillWithZeros(data, $scope.teams.length));
var dataToVisualize = [
["Teams"].concat(teamNames),
].concat(filled);
var data = new google.visualization.arrayToDataTable(dataToVisualize);
var chart = new google.visualization.LineChart(document.getElementById('heartOverviewChart'));
chart.draw(data, optionsDesktop);
},
packages: ['corechart']
});
Thank you for help! 谢谢你的帮助!
Your $scope.teams
seem to not be set properly (this will default the 'teams' property to undefined
) So when you are trying to map over the expected 'teams' array you see the error. 您的$scope.teams
似乎设置不正确(这会将'teams'属性默认设置为undefined
),因此,当您尝试映射期望的'teams'数组时,会看到错误。
Make sure your $scope
and the properties in $scope
(here $scope.teams
) are set properly before you try accessing them in the callback function. 确保你的$scope
和属性$scope
(这里$scope.teams
)正确设置您尝试访问它们在回调函数之前。
Maybe a couple of log statements or debugging it with a couple of break points might help. 也许一对夫妇的日志报表或一对夫妇的破发点,可以帮助调试它。
When I refresh or click on some other link and go back to the same link it's work great. 当我刷新或单击其他链接并返回相同的链接时,它的工作效果很好。
this might happen because by the time you perform those "other" operations the $scope.teams
might have the expected value or maybe those "other" operations are setting the $scope.teams
value. 之所以会发生这种情况,是因为在您执行这些“其他”操作时, $scope.teams
可能具有预期值,或者那些“其他”操作正在设置$scope.teams
值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.