Struc with displaying Google chart.

16 views
Skip to first unread message

Rahul Vangari

unread,
Dec 1, 2017, 3:07:28 PM12/1/17
to Google Visualization API
Hi all,

I struck with displaying google charts. Can you please help me with that.
Here is the code for Image bar:
<?php
include('db_connect.php');
$data[] = array('wonum','elapsedday');
$sql = "SELECT wonum, DATEDIFF(dt_on,dt_off) AS elapsedday from elapsed;";
$query = mysql_query($sql);
while($result = mysql_fetch_array($query))
{
$data[] = array($result['wonum'],(int)$result['elapsedday']);

}
// $data = array($data);
echo json_encode($data);
mysql_close($db);
?>

Here the code for graph.php which is used to run to display the chart:

<html>
  <head>
    <!--Load the AJAX API-->
    <script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></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 package.
    google.charts.load('current', {'packages':['corechart']});

    // Set a callback to run when the Google Visualization API is loaded.
    google.charts.setOnLoadCallback(image_chart);
   
function image_chart() {
      var jsonData = $.ajax({
          url: "imagebar.php",
          dataType: "json",
          async: false
          }).responseText;

      // Create our data table out of JSON data loaded from server.
 // alert(jsonData);return false;
      var data = new google.visualization.DataView(jsonData);

      // Instantiate and draw our chart, passing in some options.
      var chart = new google.visualization.PieChart(document.getElementById('image_div'));
      chart.draw(data, {width: 400, height: 240});
    }
</script>
</head>
<body>
<div style="font: 21px arial; padding: 10px 0 0 100px;">Image bar Chart</div>
<div id="image_div"></div>
</body>
</html>
Reply all
Reply to author
Forward
0 new messages