Skip to content Skip to sidebar Skip to footer

Dynamic Data With Google Charts

I require my Google chart to be drawn with dynamic data, so I'm storing it in a variable: var rowData = '[ [{ v: 'Mike', f: 'Mike' }, '', 'The President'], [{ v: 'Jim', f: 'Jim Vic

Solution 1:

In your first example the data is a single string, in the second example your data is a JavaScript structure of arrays and individual strings / values.

Hard to recommend a best-practice without knowing where you're dynamic data is coming from, but you should be able to remove the outermost quotes like this and have it work:

var rowData = [ [{ v: 'Mike', f: 'Mike' }, '', 'The President'], [{ v: 'Jim', f: 'Jim Vice President' }, 'Mike', 'VP'], ['Alice', 'Mike', ''], ['Bob', 'Jim', 'Bob Sponge'], ['Carol', 'Bob', ''] ];

Solution 2:

By enclosing in double-quotes rowData becomes string while the API needs Array. Use it like this

var rowData = [ [{ v: 'Mike', f: 'Mike' }, '', 'The President'], [{ v: 'Jim', f: 'Jim Vice President' }, 'Mike', 'VP'], ['Alice', 'Mike', ''], ['Bob', 'Jim', 'Bob Sponge'], ['Carol', 'Bob', ''] ];

Post a Comment for "Dynamic Data With Google Charts"