Posted By

alexstone on 10/14/10


Tagged

google array charts


Versions (?)

Google Chart from Array


 / Published in: PHP
 

Used to make a Google Pie Chart, with optional labels and size from an array, using the array keys as the labels and the values for the data.

  1. function googleChart($statsArray, $w = 300, $h = 175, $return = 'URL', $labels = true)
  2. {
  3. // Start the Google charts URL
  4. $gChartURL = "http://chart.apis.google.com/chart?cht=p&chd=t:";
  5.  
  6. // Append our values
  7. $gChartURL .= implode(',', $statsArray);
  8.  
  9. // Optionally return our labels
  10. if($labels)
  11. {
  12. $gChartURL .= '&&chdl=' . implode('|', array_keys($statsArray));
  13. }
  14.  
  15. // Set our chart size
  16. $gChartURL .= "&chs={$w}x{$h}";
  17.  
  18. if(strtoupper($return) == 'URL')
  19. {
  20. return $gChartURL;
  21. }
  22. elseif(strtoupper($return) == 'IMG')
  23. {
  24. return "<img src=\"{$gChartURL}\" width={$w} height={$h} />";
  25. }
  26. }

Report this snippet  

You need to login to post a comment.