Here is some code that is functioning properly:
Morris.Bar({
element: 'barchart',
axes: true,
data: [ json.bar.bar1 ],
xkey: 'x',
ykeys: ['y', 'z', 'a'],
labels: ['Facebook', 'LinkedIn', 'Google+'],
barColors: ['#707f9b', '#455064', '#242d3c']
});
This is the JSON data:
{
"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"
}
}
}
However, when attempting to use a loop in the code, it results in syntax errors in Dreamweaver and the output does not display on the webpage.
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']
});
The desired output should look like this:
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']
});