我有以下代碼的正常工作,迭代內部的數據:[]以JavaScript
Morris.Bar({
element: 'barchart',
axes: true,
data: [ json.bar.bar1 ],
xkey: 'x',
ykeys: ['y', 'z', 'a'],
labels: ['Facebook', 'LinkedIn', 'Google+'],
barColors: ['#707f9b', '#455064', '#242d3c']
});
THE JSON
{
"bar" :
{
"bar1" : {
"x" : "2013 Q1",
"y" : "9",
"z" : "6",
"a" : "8"
},
"bar2" : {
"x" : "2013 Q2",
"y" : "5",
"z" : "7",
"a" : "3"
},
"bar3" : {
"x" : "2013 Q3",
"y" : "8",
"z" : "9",
"a" : "6"
},
"bar4" : {
"x" : "2013 Q4",
"y" : "7",
"z" : "9",
"a" : "8"
}
}
}
然而,當我嵌入環即時顯示在Dreamweaver語法錯誤。此外,輸出不會呈現在網頁上。
Morris.Bar({
element: 'barchart',
axes: true,
data: [
for(i=1;i<=4;i++)
{
json.bar.bar + i + ','
}
],
xkey: 'x',
ykeys: ['y', 'z', 'a'],
labels: ['Facebook', 'LinkedIn', 'Google+'],
barColors: ['#707f9b', '#455064', '#242d3c']
});
的總體思路是,以使它看起來像這樣
Morris.Bar({
element: 'barchart',
axes: true,
data: [ json.bar.bar1,
json.bar.bar2,
json.bar.bar3,
json.bar.bar4 ],
xkey: 'x',
ykeys: ['y', 'z', 'a'],
labels: ['Facebook', 'LinkedIn', 'Google+'],
barColors: ['#707f9b', '#455064', '#242d3c']
});
什麼是'json.bar.bar [1-4]'? – thefourtheye
數組定義中不能有for循環。 – tewathia
你需要在Morris.Bar對象之外創建數組......然後只需將數組傳遞給data數據庫 – charlietfl