Former dataTable to JSON

532 views
Skip to first unread message

ah89

unread,
Dec 17, 2012, 7:48:08 AM12/17/12
to google-visua...@googlegroups.com
Hi,

I have a question about the combination of Google Visualization API and JSON.

At the moment I use the following DataTable for setting up a Pie Chart:

var data = new google.visualization.DataTable();
data.addColumn('string', 'Topping');
data.addColumn('number', 'Slices');
data.addRows([
            ['Mushrooms', 3],
            ['Onions', 1],
            ['Olives', 1],
            ['Zucchini', 1],
            ['Pepperoni', 2]
]);

Instead of using a DataTable, I would like to use JSON in my J2EE application.
How can I accomplish this? I know how I can setup a JSON string, but not when there are both rows and columns in play.
Hopefully someone will help me.

Thanks in advance!

Sergey Grabkovsky

unread,
Dec 17, 2012, 10:19:33 AM12/17/12
to google-visua...@googlegroups.com
Hi, I'm slightly confused by your message. Are you trying to present a Pie Chart in your Java application? If so, that is not possible. The Visualization API is JavaScript-based and cannot be used from Java unless your Java is presenting a web page.

- Sergey




--
You received this message because you are subscribed to the Google Groups "Google Visualization API" group.
To view this discussion on the web visit https://groups.google.com/d/msg/google-visualization-api/-/DBsXT8a-40MJ.
To post to this group, send email to google-visua...@googlegroups.com.
To unsubscribe from this group, send email to google-visualizati...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/google-visualization-api?hl=en.

Sergey Grabkovsky

unread,
Dec 17, 2012, 10:34:37 AM12/17/12
to google-visua...@googlegroups.com
However, you can set the DataTable from a JSON object using the JavaScript Literal Initializer, which would make your your DataTable constructor look like something like the following:
var data = new google.visualization.DataTable({
  cols: [{label: 'Topping', type: 'string'},
         {label: 'Slices', type: 'number'}],
  rows: [
    ['Mushrooms', 3],
    ['Onions', 1],
    ['Olives', 1],
    ['Zucchini', 1],
    ['Pepperoni', 2]]});

Hope this helps!

- Sergey

asgallant

unread,
Dec 17, 2012, 11:08:21 AM12/17/12
to google-visua...@googlegroups.com
Here's the documentation for creating the JSON string for a DataTable: https://developers.google.com/chart/interactive/docs/reference#dataparam
Reply all
Reply to author
Forward
0 new messages