Populate the data table with Values which i am having in Hidden field

201 views
Skip to first unread message

Lucky

unread,
Jun 6, 2012, 1:58:43 AM6/6/12
to Google Visualization API
As I am new to Use Google Chart API,
How can we bind the values which I receive from the data source to a
datatable to Google.Visualization.Datatable()

Suppose I had some values in Hidden field
Like
['Task','Hours per Day'],
['Mushrooms', 3],
['Onions', 3],
['Olives', 1],
['Zucchini', 1],
['Pepperoni', 2]

Now i want to bind these values to
var data2 = google.visualization.arrayToDataTable([]);

It works fine for below when I specify the values like this
var data2 = google.visualization.arrayToDataTable([
['Country', 'Population', 'Area'],
['CN', 1324, 9640821],
['IN', 1133, 3287263],
['US', 304, 9629091],
['ID', 232, 1904569],
['BR', 187, 8514877]
]);

how can I bind these values to google.visualization.arrayToDataTable()
I had tried
var T =$("#hidChartData").val();

var data = google.visualization.arrayToDataTable(T) does not
support .

or

var data = google.visualization.DataTable(T) also does not
support

Please help me out .

visigoth

unread,
Jun 7, 2012, 7:16:00 AM6/7/12
to google-visua...@googlegroups.com
I'm not sure what the source of the problem is (if you send me a simple example page I will debug it), but have you tried using setRows() instead?
That is:
var data = new google.visualization.DataTable();
data.setColumn(...);
...
data.setRows(hiddenFieldData);

asgallant

unread,
Jun 7, 2012, 9:55:19 AM6/7/12
to google-visua...@googlegroups.com
Most likely, the value pulled from the HTML element is being interpreted as a string.  You might be able to get it to work by using eval() on the input before passing it to the #arrayToDataTable method:

var data = google.visualization.arrayToDataTable(eval(T)); 
Reply all
Reply to author
Forward
0 new messages