Hi, new here. I'm trying to build a Google Charts application that gets
its data from a REST API built in Java.
Question 1 is, can anybody point me to some documentation on what needs to
be returned from the Java side? I should probably start by reading up but
so far everything I've found is concerned with the javascript side of
things, or on building a REST service in PHP.
More specifically, here is what I have tried and why it's not working:
My javascript code looks like this:
<script type="text/javascript">
google.load("visualization", "1", {packages:["corechart"]});
google.setOnLoadCallback(drawChart);
function drawChart() {
var jsonData = $.ajax({
url: "/rrportal-trd/api/productMetrics/activeCampaigns",
dataType:"json",
async: false
}).responseText;
// Create our data table out of JSON data loaded from server.
var data = new google.visualization.DataTable(jsonData);
var options = {
title: 'Active Campaigns'
};
var chart = new
google.visualization.LineChart(document.getElementById('chart_div'));
chart.draw(data, options);
}
</script>
I first tried hard-coding the JSON as a String, basically as a 'hello
world' first try:
return "{" +
" 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}]}" +
" ]" +
"}";
but this line barfed on the response:
var data = new google.visualization.DataTable(jsonData);
HOWEVER, if I grab the response from Chrome developer tools and paste it
directly into the javascript, then reload the page, it works perfectly:
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}]} ]});
Any idea what's needed to make that work?
Now I'm trying to build the response using google.visualization.DataTable
and have a question about that, but this post is already very long, I will
save that for another one.
--
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.