views:

34

answers:

1

Hello,

I read that JSON can be inserted into a datatable. However, its done in JS on the HTML page (if memory serves right). I am using the GWT- visualisation driver as given here, and the only methods to add a row are not designed with JSON in mind. Is there any work-able solution? I am trying to make a Stacked Column Chart. Thanks.

+1  A: 

I also struggled with this using geomap and data table combined. In my workaround I used the evalJSON() in prototype javascript framework to make the json string an object.

var country_obj = country_data.evalJSON(true);

Then I loop over the object's length :

var data = new google.visualization.DataTable();
data.addRows(country_obj.country.length);
data.addColumn('string', 'Country');
data.addColumn('number', map_context); 

var j = country_obj.country.length;
for ( i = 0; i < j; i++ )
{
    var num = new Number(country_obj.country[i].geo_mstat_reads);

    data.setValue(i, 0, country_obj.country[i].country_name);
    data.setValue(i, 1, num.valueOf());
}

// and then the table.draw() with the data

This worked very well for me because it scales to the exact size of the dataset you are trying to show.

Also you can do a whole whack of operations on an object which makes your life and coding easier to read and write.

I hope this helps you with your problem.

etbal
I cant do that in java, it seems.
Kaustubh P
this is javascript
etbal