Json File Call Example

884 views
Skip to first unread message

Alexandre Rodrigues

unread,
Jul 23, 2019, 6:26:58 PM7/23/19
to Google Visualization API

Hi all, Since I can use google charts with the json file below, I am unable to make his call. I would like to have an example that works.


json file:
google.visualization.Query.setResponse( { version: "0.7", status: "ok", reqId: 0, table: { cols: [ {id: "DATE", label: "DATE", type: "string"}, {id: "TOTAL", label: "TOTAL", type: "string"} ], rows: [ {c: [ {v: "01\/07\/19"}, {v: "19506"} ]} ,{c: [ {v: "02\/07\/19"}, {v: "19409"} ]} ,{c: [ {v: "03\/07\/19"}, {v: "18380"} ]} ,{c: [ {v: "04\/07\/19"}, {v: "19423"} ]} ,{c: [ {v: "05\/07\/19"}, {v: "20851"} ]} ,{c: [ {v: "06\/07\/19"}, {v: "15379"} ]} ,{c: [ {v: "07\/07\/19"}, {v: "6227"} ]} ,{c: [ {v: "08\/07\/19"}, {v: "20324"} ]} ,{c: [ {v: "09\/07\/19"}, {v: "19955"} ]} ,{c: [ {v: "10\/07\/19"}, {v: "22530"} ]} ,{c: [ {v: "11\/07\/19"}, {v: "10266"} ]} ,{c: [ {v: "12\/07\/19"}, {v: "19304"} ]} ,{c: [ {v: "13\/07\/19"}, {v: "14530"} ]} ,{c: [ {v: "14\/07\/19"}, {v: "5820"} ]} ,{c: [ {v: "15\/07\/19"}, {v: "21763"} ]} ,{c: [ {v: "16\/07\/19"}, {v: "23497"} ]} ,{c: [ {v: "17\/07\/19"}, {v: "21897"} ]} ,{c: [ {v: "18\/07\/19"}, {v: "21124"} ]} ,{c: [ {v: "19\/07\/19"}, {v: "20228"} ]} ,{c: [ {v: "20\/07\/19"}, {v: "13727"} ]} ,{c: [ {v: "21\/07\/19"}, {v: "4340"} ]} ] } } )

Joe Finnegan

unread,
Jul 24, 2019, 9:26:24 AM7/24/19
to google-visua...@googlegroups.com
Hey Alexandre, 

You don't need to use this like normal JSON - You can use the getDataTable function to create a data table out of the response - try something like this: 

var data = response.getDataTable();

You can then use the 'data' variable directly in a draw function like this: 

table.draw(data);

Let me know if this is helpful

--
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 google-visualizati...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/google-visualization-api/820b384e-1c30-42f2-97d4-d02e846d1328%40googlegroups.com.


--
IT Service Coordinator | College of Science and Engineering | cse.umn.edu
University of Minnesota - Twin Cities Campus | umn.edu
finn...@umn.edu | 612-624-7588 | Keller Hall 1-229

Alexandre Rodrigues

unread,
Jul 24, 2019, 2:53:58 PM7/24/19
to Google Visualization API
Joe, good afternoon! 

Thanks for the feedback. 

I do not have much experience with google charts and am trying to learn more, stutter this Json from an oracle query and I am not able to hold his event, see an example of how I can make a call "google.visualization.Query. setResponse ({…}); ", Can you help if possible?

Sources:

Here's the code if it helps to figure out what I'm doing wrong:

<html>
  <head>
    <title>
      Google Visualization API Sample
    </title>
    <script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.0/jquery.min.js"></script>
    <script type="text/javascript">
     
google.charts.load('current', {'packages':['table']});
     google.charts.setOnLoadCallback(drawTable);

      function drawTable() {
 
      var myView = google.visualization.DataView.fromJSON(data, viewAsJson);
  
  DataView.toJSON(google.visualization.Query.setResponse(
{
version: "0.7",
status: "ok",
reqId: 0,
table: {
  cols: [
   {id: "DAT_CRIACAO_FIDELIZACAO", label: "DAT_CRIACAO_FIDELIZACAO", type: "string"},
));
  
     var table = new google.visualization.Table(document.getElementById('table_div'));

     table.draw(data,{showRowNumber: true, width: '100%', height: '100%'});
      }
    </script>
  </head>
  <body>
    <div id="table_div" style="width: 900px; height: 500px"></div>
  </body>
</html>
Reply all
Reply to author
Forward
0 new messages