我想为图表动态创建我的数据集。现在我得到了这样的东西,它按预期工作,但我不知道数组的长度,所以我不能使用它,当我在数据对象中尝试循环时它失败了。有什么建议吗?
var month=new Array("Jan","Feb","Mar","Apr","Maj","Jun","Jul","Aug","Sep","Okt","Nov","Dec");
var day =new Array();
var mon =new Array();
var pass =new Array();
var bug =new Array();
_.each(data, function(data){
var date = new Date(data['timestamp']);
mon.push(date.getMonth());
day.push(date.getDate());
pass.push(data['pass']);
bug.push(data['bug']);
});
var datasets = {
"Pass": {
label: "Pass",
data: [[""+month[mon[0]]+"-"+day[0]+"", pass[0]], [""+month[mon[1]]+"-"+day[1]+"", pass[1]], [""+month[mon[2]]+"-"+day[2]+"", pass[2]], [""+month[mon[3]]+"-"+day[3]+"", pass[3]], [""+month[mon[4]]+"-"+day[4]+"", pass[4]]]
},
"Bug": {
label: "Bug",
data: [[""+month[mon[0]]+"-"+day[0]+"", bug[0]], [""+month[mon[1]]+"-"+day[1]+"", bug[1]], [""+month[mon[2]]+"-"+day[2]+"", bug[2]], [""+month[mon[3]]+"-"+day[3]+"", bug[3]], [""+month[mon[4]]+"-"+day[4]+"", bug[4]]]
}
};