Read data from database and view in chart

32 views
Skip to first unread message

Razee Hussein-Jamal

unread,
Aug 11, 2013, 6:22:26 AM8/11/13
to google-visua...@googlegroups.com
Currently developing a website where I query data from a mysql database and encode it to JSON string, I want to view the data using the google charts and tables.

At the moment I can't view the data in the tables but the JSON string output seems to be correct.

Here is the javascript code:

<script type="text/javascript">
    function drawVisualization() {

        var jsonData = $.ajax({
          url: "dataTableViewDaily.php", // make this url point to the data file
          dataType: "json",
          async: false
        }).responseText;
    var data = new google.visualization.DataTable(jsonData);

    
      // Create and draw the visualization.
      visualization = new google.visualization.Table(document.getElementById('table'));
      visualization.draw(data, null);
    }
    

    google.setOnLoadCallback(drawVisualization);
    </script>

dataTableViewDaily.php echo the json string.

Would appreciate any help, thank you


asgallant

unread,
Aug 11, 2013, 12:23:52 PM8/11/13
to google-visua...@googlegroups.com
You might just have left it out of the post, but your code is missing the google.load call that loads the Visualization API, so make sure you have that.  If that's not the problem, post a copy of the JSON output by the "dataTableViewDaily.php" script so I can verify that it is in the correct format.  Also, open the page in Chrome or Firefox and check the developer's console to see if there are any error messages displayed.

Razee Hussein-Jamal

unread,
Aug 11, 2013, 2:19:01 PM8/11/13
to google-visua...@googlegroups.com
Yes, I have the google.load inside the script.

This is the error I receive: Error: Invalid JSON string: error: 1046

And this is the JSON string that is echo inside the dataTableViewDaily.php

{"cols":[{"id":"A","label":"Date","type":"string"},{"id":"B","label":"User","type":"string"},{"id":"C","label":"Cement Brand","type":"string"},{"id":"D","label":"Volume","type":"string"},{"id":"E","label":"Type","type":"string"}],"rows":[{"c":[{"v":"08-06-2013"},{"v":"raze...@gmail.com"},{"v":"Muthana"},{"v":"27"},{"v":"Local Plant"}]},{"c":[{"v":"08-06-2013"},{"v":"raze...@gmail.com"},{"v":"Samawa"},{"v":"28"},{"v":"Local Plant"}]}]}

Thank you


--
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/fiy-6Llj_6A/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.
 
 



--
Razee Hussein-Jamal
Masters in Embedded Systems,
Department of Information Technology,
Uppsala University - Sweden
Mobile Phone : +46764158553 (Sweden) , +9647701524721 (N.Iraq), +905058622477 (Turkey)

Razee Hussein-Jamal

unread,
Aug 11, 2013, 3:41:09 PM8/11/13
to google-visua...@googlegroups.com
there seems to be a problem when I echo json string in the dataTableViewDaily.php file as the JSON string seems to be correct, so this is a small part of the code I have:

$jsonObj = json_encode($table);

header('Cache-Control: no-cache, must-revalidate');
header('Content-type: application/json');


echo $jsonObj;



Reply all
Reply to author
Forward
0 new messages