Google Chart sample class
Simple class that uses
Google Chart API for generating simple charts at paster.cz
<?php // (c) 2008 sh(a)isecure.cz
class myGoogleChart
{
var $data = array();
public function addPair($label, $value) {
$this->data[$label] = $value;
}
public function getImageUrl() {
$keys = array();
$vals = array();
foreach($this->data as $key => $val) {
$keys[] = $key;
$values[] = $val;
}
$maxValue = max($values);
// A list of encoding characters to help later, as per Google's example
$simpleEncoding = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
$chartData = "s:";
for ($i = 0; $i < count($values); $i++) {
$currentValue = $values[$i];
if ($currentValue > -1) {
$chartData.=substr($simpleEncoding,61*($currentValue/$maxValue),1);
} else {
$chartData.='_';
}
}
//http://chart.apis.google.com/chart?cht=p3&chd=s:52,1367&chs=310x130&chl=Hello|World"
return 'http://chart.apis.google.com/chart?cht=p3&chs=310x130&chd='.$chartData.'&chl='.implode('|',$keys);
}
}
?>
Tagy:
php 40 řádků | 2008-02-04 20:12:48 | air.kadlec@seznam.cz