This is the problem:

var data = google.visualization.arrayToDataTable([testArray]);

you don't want the brackets around testArray.  It should look like this:

var data = google.visualization.arrayToDataTable(testArray);

On Friday, March 14, 2014 4:38:41 PM UTC-4, Captain Gordon Freeman wrote:
>
> Is there a way to dynamically build a bar chart without entering 
> everything manually? I have an array that houses the data needed for the 
> creation of the bar chart. Could I loop through it and display it that way? 
> Below is some code to help explain what I'm attempting to do:
>
> The normal way of setting up the data section is like this:
>
> var data = google.visualization.arrayToDataTable([
>         ["Section", "Number1", { role: 'style', type: 'string' }, 
> "Number2", { role: 'style', type: 'string' }],
>         ["Section 1", 1, '#391cb0', 5, '#c70063'],
>         ["Section 2", 2, '#391cb0', 6, '#c70063'],
>         ["Section 3", 3, '#391cb0', 7, '#c70063'],
>         ["Section 4", 4, '#391cb0', 8, '#c70063'],
>     ]);
>
>
>
> This is what I'm looking to do:
>
> var testArray = [];
>     testArray[0] = ["Section", "Number1", { role: 'style', type: 'string' 
> }, "Number2", { role: 'style', type: 'string' }];
>     for (var i = 0; i < finalArray.length; i++) {
>         testArray.push(finalArray[i]);
>     }
>
>     var data = google.visualization.arrayToDataTable([testArray]);
>
> It creates an array with all the data in it like the first example. Note 
> the finallArray value contains the following:
>
> ["Section 1", 1, '#391cb0', 5, '#c70063'],
>
>           ["Section 2", 2, '#391cb0', 6, '#c70063'],
>           ["Section 3", 3, '#391cb0', 7, '#c70063'],
>           ["Section 4", 4, '#391cb0', 8, '#c70063'],
>
>
>
> The chart does not like what I attempted. The only way that I can get the 
> data from the array to show is like this:
>
> var data = google.visualization.arrayToDataTable([
>         ["Section", "Number1", { role: 'style', type: 'string' }, 
> "Number2", { role: 'style', type: 'string' }],
>         finalArray[0],
>         finalArray[1],
>         finalArray[2],
>         finalArray[3],
>     ]);
>
> Now that's not bad because I know it works. The issue is because the 
> length of the finalArray variable isn't static. So is it possible to 
> dynamically build the chart?
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google Visualization API" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to