我正在创建一个使用jquery加载XML数据的条形图。但出于某种原因,我得到TypeError: rawData[row] is undefined
。这里的代码可行,行中发生的事情是获取日期,它将日期分为月份和年份,并将其解析为int。所以2016年4月21日它将获得04并将其解析为int。
rawData= [
['Month', 'Identified transaction', 'Identified counterparty, verification needed', 'Unidentified transaction'],
['Jan', 0, 0, 0],
['Feb', 0, 0, 0],
['Mar', 0, 0, 0],
['Apr', 0, 0, 0],
['May', 0, 0, 0],
['Jun', 0, 0, 0],
['Jul', 0, 0, 0],
['Aug', 0, 0, 0],
['Sept', 0, 0, 0],
['Oct', 0, 0, 0],
['Nov', 0, 0, 0],
['Dec', 0, 0, 0]
];
<!-- loop for each row -->
xmlData.find('item').each(function(){
var col;
var row;
/* loop for each column */
$j(this).find('column').each(function(){
var colID = $j(this).attr("columnid");
/* Get value and store in variable */
var value = $j(this).find('displayData').text();
/* Selecting specific column */
if(colID == columns["Category"]){
/* Compare value to String element and store the information in the template */
if(value === "Identified transaction"){
col = rawData[0].indexOf("Identified transaction");
}else if(value === "Identified transaction above threshold"){
col = rawData[0].indexOf("Identified transaction");
}else if(value === "Identified transaction, unidentified type"){
col = rawData[0].indexOf("Identified transaction");
}else if(value === "Identified transaction, above cumulative threshold"){
col = rawData[0].indexOf("Identified transaction");
}else if(value === "Identified transaction, frequency limit"){
col = rawData[0].indexOf("Identified transaction");
}else if(value === "Identified transaction, unidentified currency"){
col = rawData[0].indexOf("Identified transaction");
}else if(value === "Identified counterparty frequency limit"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty unidentified type"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty unidentified amount"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty, unidentified transaction, above overall threshold"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty, unidentified transaction, within overall threshold"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty, unidentified amount, above overall threshold"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty, unidentified amount, within overall threshold"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty, unidentified amount, above overall threshold"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Identified counterparty, unidentified amount, within overall threshold"){
col = rawData[0].indexOf("Identified counterparty, verification needed");
}else if(value === "Unidentified transaction"){
col = rawData[0].indexOf("Unidentified transaction");
}else if(value === "Unidentified counterparty"){
col = rawData[0].indexOf("Unidentified transaction");
}else if(value === "Unidentified transaction, within overall threshold"){
col = rawData[0].indexOf("Unidentified transaction");
}
}
<!-- dividing the data so it does not end up all in 1 bar. The divider here is the date of when an transaction was created -->
else{
var date = $j(this).find('displayData').text();
var res = date.split("/");
row = parseInt(res[1]);
}
})
rawData[row][col]++;
})
drawStacked(rawData);
但是现在我正在尝试基于另一个单词作为字符串。这是我如何处理它的一个例子:
else{
var ID;
if(value == "Jan"){
ID = 1;
} if(value == "Feb"){
ID = 2;
} if(value == "Mar"){
ID = 3;
} if(value == "Apr"){
ID = 4;
} if(value == "May"){
ID = 5;
} if(value == "Jun"){
ID = 6;
} if(value == "Jul"){
ID = 7;
} if(value == "Aug"){
ID = 8;
} if(value == "Sept"){
ID = 9;
} if(value == "Oct"){
ID = 10;
}
row = ID;
}
我在这里做错了什么?