Charts do not appear, only a blank page

547 views
Skip to first unread message

Amanda Beloli

unread,
Jan 12, 2014, 10:48:28 PM1/12/14
to google-visua...@googlegroups.com
Hi all,

I'm almost sure that my json table generated by my script.php is right:

{"cols":[{"label":"idade","type":"number"},{"label":"quantidade","type":"number"}],"rows":[{"c":[{"v":"19"},{"v":1}]},{"c":[{"v":"20"},{"v":1}]},{"c":[{"v":"25"},{"v":1}]},{"c":[{"v":"37"},{"v":1}]},{"c":[{"v":"45"},{"v":2}]}]}

But anything appear when I tried to create the chart, by means of the code below. Anybody knows the problem?

<html>
  <head>
    <!--Load the AJAX API-->
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
    <script type="text/javascript">
    
    // Load the Visualization API and the piechart package.
    google.load('visualization', '1', {'packages':['corechart']});
      
    // Set a callback to run when the Google Visualization API is loaded.
    google.setOnLoadCallback(drawChart);
      
    function drawChart() {
      var jsonData = $.ajax({
          url: "script.php",
          dataType:"json",
          async: false
          }).responseText;
          
      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(jsonData);
      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart.draw(data, {width: 400, height: 240});
    }
    </script>
  </head>
  <body>
    <!--Div that will hold the pie chart-->
    <div id="chart_div"></div>
  </body>
</html>

I suppose it is not the problem, but I'm using wamp server... not using databases, json and these stuffs, google charts works nicely with php in wamp.

Thank you in advance.

asgallant

unread,
Jan 13, 2014, 10:37:35 AM1/13/14
to google-visua...@googlegroups.com
PieCharts require one string column and one number column - you have two number columns.  Change the type of the first column to "string" and it should work (the values in that column are already strings, so it should be fine):

{"label":"idade","type":"string"}

Amanda Beloli

unread,
Jan 13, 2014, 11:18:42 AM1/13/14
to google-visua...@googlegroups.com
Thank you a lot, it solved the problem! :)

Atenciosamente,

Amanda Beloli
Engenharia Elétrica
Universidade do Estado de Santa Catarina


2014/1/13 asgallant <drew_g...@abtassoc.com>

--
You received this message because you are subscribed to a topic in the Google Groups "Google Visualization API" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/google-visualization-api/Eocu0ZdBW2M/unsubscribe.
To unsubscribe from this group and all its topics, send an email to google-visualizati...@googlegroups.com.
To post to this group, send email to google-visua...@googlegroups.com.
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages