Return to Snippet

Revision: 33829
at October 14, 2010 01:20 by alexstone


Initial Code
function googleChart($statsArray, $w = 300, $h = 175, $return = 'URL', $labels = true)
  {
    // Start the Google charts URL
    $gChartURL = "http://chart.apis.google.com/chart?cht=p&chd=t:";
    
    // Append our values
    $gChartURL .= implode(',', $statsArray);
    
    // Optionally return our labels
    if($labels)
    {
      $gChartURL .= '&&chdl=' . implode('|', array_keys($statsArray));
    }
    
    // Set our chart size
    $gChartURL .= "&chs={$w}x{$h}";
    
    if(strtoupper($return) == 'URL')
    {
      return $gChartURL;
    }
    elseif(strtoupper($return) == 'IMG')
    {
      return "<img src=\"{$gChartURL}\" width={$w} height={$h} />";
    }
  }

Initial URL

                                

Initial Description
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.

Initial Title
Google Chart from Array

Initial Tags
google, array

Initial Language
PHP