It looks like you are trying to do something like you might with a template
language. Javascript by itself doesn't work that way, however. You'll
need to do something like this instead:
var dataArray = ['Age', 'Weight'];
for(var i=0;i<arr1.length;i++) {
dataArray.push( [eval(arr1[i]),eval(arr2[i])] );
}
var data = google.visualization.arrayToDataTable(dataArray);
On Mon, Oct 29, 2012 at 2:34 AM, Bhaskar Chaudhary <[email protected]>wrote:
> Hi
>
> Need help with data insertion into google charts.
>
> Taken this from documentation example.
>
> var data = google.visualization.arrayToDataTable([
>> ['Age', 'Weight'],
>> [ 8, 12],
>> [ 4, 5.5],
>> [ 11, 14]
>> ]);
>>
>
> when i replace this with array
>
> var data = google.visualization.arrayToDataTable([
>> ['Age', 'Weight'],
>> [eval(arr1[0]),eval(arr2[0])]
>> [eval(arr1[1]),eval(arr2[1])]
>> [eval(arr1[2]),eval(arr2[2])]
>>
>> ]);
>
> it still works. But when i replace it with a for loop:
>
> var data = google.visualization.arrayToDataTable([
>>> ['Age', 'Weight'],
>>> for(var i=0;i<arr1.length;i++) {
>>> [eval(arr1[i]),eval(arr2[i])],
>>> }
>>>
>>> ]);
>>>
>>
> I get a syntax error message in javascript error console pointing at the
> start of the 'for' loop.
> What am i doing wrong ?
>
>
> Any help is greatly appreciated. Thanks a lot !
>
> --
> You received this message because you are subscribed to the Google Groups
> "Google Chart API" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/google-chart-api/-/lyb8Mkku7Q4J.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/google-chart-api?hl=en.
>
--
Daniel LaLiberte <https://plus.google.com/100631381223468223275?prsrc=2> -
978-394-1058
[email protected] <[email protected]> 562D 5CC, Cambridge MA
[email protected] <[email protected]> 9 Juniper Ridge
Road, Acton MA
--
You received this message because you are subscribed to the Google Groups
"Google Chart API" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-chart-api?hl=en.