I'm trying to display the following data in  the column chart. When I used 
the below php code the chart is not displayed

SQL output

Year Month  Count
1011 01 760
1011 02 2439
1011 03 764
1011 10 14
1011 11 562
1011 12 794
1112 01 891
1112 02 3428
1112 03 2256
1112 10 59
1112 11 379
1112 12 365
1213 01 1228
1213 02 3649
1213 03 892
1213 10 296
1213 11 1020
1213 12 793
1314 01 1019
1314 02 5027
1314 03 1439
1314 10 436
1314 11 695
1314 12 826
1415 01 1332
1415 02 1775
1415 10 449
1415 11 941
1415 12 937

Column chart format

         ['Year', 'Oct', 'Nov', 'Dec', 'Jan', 'Feb', 'Mar'],
         ['1011',  0,     0,     402,   760,   2439,  753],
          ['1112',  0,     379,   365,   891,   3428,  1007],
          ['1213',  136,   904,    735,  1173,  3553,  763],
          ['1314',  210,   516,    698,  823,   4748,  1439],
          ['1314',  449,   941,    937,  1332,  1775,  0]

Code:

<?php
// https://developers.google.com/chart/interactive/docs/php_example



$rows = array();
$table = array();
$table['cols'] = array(

    // Labels for your chart, these represent the column titles
    
array('label' => 'AidYear', 'type' =>'string'),
array('label' => 'Jan', 'type' => 'number'),
array('label' => 'Feb', 'type' => 'number'),
array('label' => 'Mar', 'type' => 'number'),
       array('label' => 'Oct', 'type' => 'number'),
array('label' => 'Nov', 'type' => 'number'),
array('label' => 'Dec', 'type' => 'number'),

);
$temp = array();
$PrevYear = '0';
$i = 0;
 $CountQuery = "select year, month, count from table;

while($r = oci_fetch_array($CountQuery)) {
// values for the chart
$CurYear = $r['YEAR'];
if ($CurYear != $PrevYear) {
$i++;
$j = 0;
$temp[$i][$j] = array('v' => (string) $r['YEAR']);
$PrevYear = $CurYear;
$j++;

}
if ($CurYear == $PrevYear) { 
//echo "$i    $j   ".$r['YEAR'].   $r['COUNT'] ."<br>";
switch ($r['MONTH']) {
case '01':
$temp[$i][$j] = array('v' => (int) $r['COUNT']); 
break;
case '02':
$temp[$i][$j] = array('v' => (int) $r['COUNT']); 
break;
case '03':
$temp[$i][$j] = array('v' => (int) $r['COUNT']); 
break;
case '10':
$temp[$i][$j] = array('v' => (int) $r['COUNT']); 
break;
case '11':
$temp[$i][$j] = array('v' => (int) $r['COUNT']); 
break;
case '12':
$temp[$i][$j] = array('v' => (int) $r['COUNT']); 
break;
default:
//echo "The Month is not between OCT and MAR <br>";
$temp[$i][$j] = array('v' => (int) $r['COUNT']);
}
$j++;
}
}

$rows = $temp;
 print_r($jsonTable);


?>
<html>
  <head>
    <script type="text/javascript" 
src="https://www.google.com/jsapi";></script>
<script type="text/javascript" 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.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: "getData.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: 800, height: 600});
    }

    </script>  

   <script type="text/javascript">
   
    </script>
  </head>
  <body>
   <div id="chart_div"></div>
  </body>
</html>

-- 
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-visualization-api.
For more options, visit https://groups.google.com/d/optout.

Reply via email to