Pie Chart using PHP and MySql
<p>I'm trying to draw a <code>Pie Chart</code> with my database. I used Google <code>Pie Chart</code> , <code>PHP</code> and <code>MySql</code>.
I run the code doesn't show any errors but I don't see pie chart showing up. 
Can please someone tell me where to modify to make it work? 
Thanks.</p>

<pre><code>    &lt;?php
    /* Your Database Name */
$dbname = 'chart';
$username = 'root';
$password = '';

try {
  /* Establish the database connection */
  $conn = new PDO("mysql:host=localhost;dbname=$dbname", $username, $password);
  $conn-&gt;setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

  /* select all the weekly tasks from the table googlechart */
  $result = $conn-&gt;query('SELECT Nature, concat((count( * ) *100 / (SELECT count( * ) FROM `tfichiers`)) , "%") AS percent FROM `tfichiers` GROUP BY Nature ');
  $rows = array();
  $table = array();
  $table['cols'] = array(

    // Labels for your chart, these represent the column titles.
    /* 
        note that one column is in "string" format and another one is in "number" format 
        as pie chart only required "numbers" for calculating percentage 
        and string will be used for Slice title
    */

    array('label' =&gt; 'Nature', 'type' =&gt; 'string'),
    array('label' =&gt; 'percent', 'type' =&gt; 'number')

);
    /* Extract the information from $result */
    foreach($result as $r) {

      $temp = array();

      // the following line will be used to slice the Pie chart

      $temp[] = array('v' =&gt; (string) $r['Nature']); 

      // Values of each slice

      $temp[] = array('v' =&gt; (int) $r['percent']); 
      $rows[] = array('c' =&gt; $temp);
    }

$table['rows'] = $rows;

// convert data into JSON format
$jsonTable = json_encode($table);
//echo $jsonTable;
} catch(PDOException $e) {
    echo 'ERROR: ' . $e-&gt;getMessage();
}
 ?&gt;
&lt;html&gt;
  &lt;head&gt;
    &lt;!--Load the Ajax API--&gt;
    &lt;script type="text/javascript" src="https://www.google.com/jsapi"&gt;&lt;/script&gt;
    &lt;script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"&gt;&lt;/script&gt;
    &lt;script type="text/javascript"&gt;

    // 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() {

      // Create our data table out of JSON data loaded from server.
      var data = new google.visualization.DataTable(&lt;?=$jsonTable?&gt;);
      var options = {
           title: 'Demande par Nature',
          is3D: 'true',
          width: 800,
          height: 600
        };
      // Instantiate and draw our chart, passing in some options.
      // Do not forget to check your div ID
      var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
      chart.draw(data, options);
    }
    &lt;/script&gt;
  &lt;/head&gt;

  &lt;body&gt;
    &lt;!--this is the div that will hold the pie chart--&gt;
    &lt;div id="chart_div"&gt;&lt;/div&gt;
  &lt;/body&gt;
&lt;/html&gt;
</code></pre>