When you get the responseText of the AJAX call, it is a string, which must 
be parsed as JSON.  Your string construction, however, is not valid JSON 
(object keys and strings must be double-quoted, dates must be entered as 
strings like "Date(2014, 6, 23)").  When you copy the string into 
javascript like your example, it is valid, because you are pasting a 
javascript object that way, not a JSON string.  A properly analagous test 
would be to put quotes around the object:

var data = new google.visualization.DataTable("{  cols: [{id: 'date', 
label: 'Date', type: 'string'},         {id:        'activeCampaigns', 
label: 'Active Campaigns', type: 'number'}        ],  rows: [{c:[{v: new 
Date(2014, 6, 22), f:        '2/28/08'}, {v: 393}]},         {c:[{v: new 
Date(2014, 6, 23), f: '2/28/08'}, {v: 412}]}        ]}");

which fails.

Since you are using Java, I recommend importing either the jackson or gson 
libraries to perform JSON encoding of POJOs into JSON strings.  You can 
then construct a Java object to represent your data and use the libraries 
to convert it to JSON for you.  Here's a rough start on what such an object 
might look like:

public class DataTable {
    private List<Column> cols; // list of columns
    private List<Row> rows; // list of rows
    
    // constructor, getters, and setters
    
    private class Column {
        private String type; // type of column
        private String id; // id of column
        private String label; // label of column
        private Map<String, Object> p; // properties of column
        
        // constructor, getters, and setters
    }
    
    private class Row {
        private List<Cell> c; // list of cells
        private Map<String, Object> p; // properties of row
        
        // constructor, getters, and setters
        
        private class Cell {
            private Object v; // value of cell
            private string f; // formatted value of cell
            private Map<String, Object> p; // properties of cell
            
            // constructor, getters, and setters
        }
    }
}

You also may want to look into the Java DataSource Library 
<https://developers.google.com/chart/interactive/docs/dev/dsl_intro>, which 
is intended to implement the data source protocol, but can probably be used 
piecemeal for custom projects as well.

On Tuesday, June 24, 2014 8:22:05 PM UTC-4, Anthony Zepezauer wrote:
>
>
> Re-reading my own post, I'm not sure if I was clear:  The code snippet 
>> that begins with
>>
>
>      return "{" + 
>
> is Java code; it's what is returned by the api call 
>
>            /rrportal-trd/api/productMetrics/activeCampaigns
>
>

-- 
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