1
無法使dygraphs正常工作。dygraphs數組中的標籤數量和列數之間的不匹配
我有從PHP,看起來像填充的數組:
data = [
{
"DATA": "2016-01-22",
"TOTAL": [
"7",
"4",
"20",
"0"
]
},
{
"DATA": "2016-01-25",
"TOTAL": [
"3",
"2",
"10",
"0"
]
},
{
"DATA": "2016-01-26",
"TOTAL": [
"1",
"1",
"4",
"0"
]
},
{
"DATA": "2016-01-27",
"TOTAL": [
"2",
"1",
"2",
"0"
]
},
{
"DATA": "2016-02-02",
"TOTAL": [
"1",
"1",
"1",
"0"
]
},
{
"DATA": "2016-02-10",
"TOTAL": [
"1",
"1",
"3",
"0"
]
}
]
我然後生成該數據的曲線圖:
data.forEach(function(item) {
var adata = item.DATA;
var atotal = item.TOTAL;
graphstr1 += '[new Date("' + adata + '"),' + atotal + '],';
});
graphstr1 = graphstr1.slice(0, -1);
console.log(graphstr1);
尋找在控制檯中,數據是在所要求的格式,但我總是得到錯誤問題標題
Dygraph代碼:
g = new Dygraph(
document.getElementById("graphdiv"), [
graphstr1,
/*[new Date("2016-01-22"), 7, 4, 20, 0],
[new Date("2016-01-25"), 3, 2, 10, 0],
[new Date("2016-01-26"), 1, 1, 4, 0],
[new Date("2016-01-27"), 2, 1, 2, 0],
[new Date("2016-02-02"), 1, 1, 1, 0],
[new Date("2016-02-10"), 1, 1, 3, 0]*/
], {
labels: ["x", "Registados", "Grávidas", "Com Filhos", "Sem Filhos"]
}
);
想你的代碼,但仍然得到錯誤:標籤的數量之間不匹配(X,Registados,孕婦,玉米FILHOS,SEM FILHOS)和陣列 – mjpramos
@mjpramos列數,它看起來適合我。 –
該死!它在行動! :)我看到我的問題是使用:g = new Dygraph(document.getElementById(「graphdiv」),[graphstr1] ...而不是g = new Dygraph(document.getElementById(「graphdiv」),graphstr1 – mjpramos