在设置数组时使用变量时,我通过一段脚本遇到错误。如果我只是用它们拥有的数值替换变量(我已经验证过),我不会收到错误消息。
设置这样的数组有什么问题吗?
arrayOfData = new Array(
[leftAmount, 'Get', '#2697C9'],
[middleAmount, 'Neutral', '#E7E7E7'],
[rightAmount, 'Don\'t Get', '#EB5830']
);
如果有帮助,您可以查看整个功能
function generateChart(viewerObj){
if(viewerObj.getActiveUsers){
var leftAmount = viewerObj.getActiveUsers;
}
else{
window.leftAmount = 0;
}
if(viewerObj.getActiveUsers){
var middleAmount = viewerObj.getActiveUsers;
}
else{
var middleAmount = 0;
}
if(viewerObj.dontGetActiveUsers){
var rightAmount = viewerObj.dontGetActiveUsers;
}
else{
var rightAmount = 0;
}
arrayOfData = new Array(
[leftAmount, 'Get', '#2697C9'],
[middleAmount, 'Neutral', '#E7E7E7'],
[rightAmount, 'Don\'t Get', '#EB5830']
);
$('.divGraph').jqBarGraph({ data: arrayOfData });
}