'PieChart',
'bar' => 'BarChart',
'area' => 'AreaChart',
'gauge' => 'Gauge',
'orgchart' => 'OrgChart',
'column' => 'ColumnChart',
'line' => 'LineChart',
'timeline' => 'AnnotatedTimeLine',
'intensitymap' => 'IntensityMap',
);
function googlevis($type) {
$this->mode($type);
$this->columns=array();
$this->rows=array();
// setup default options
$this->setTitle("Unnamed");
$this->setLegend("right");
$this->setWidth(400);
$this->setHeight(240);
}
function mode($type) {
if (!empty($this->charts[$type])) {
$this->type = $this->charts[$type];
} else {
$this->error("Unknown chart type - $type");
}
}
function addColumn($name,$type) {
if ($type==='string' || $type==='number' || $type==='boolean' || $type==='date' || $type==='datetime' || $type==='timeofday') {
$this->columns[]=array($name,$type);
}else {
$this->error("Unknown column type - $type");
}
}
function setRawOption($key,$value) {
$this->options[$key]=$value;
}
function addRow($data) {
$this->rows[]=$data;
}
function setTitle($text) {
$this->setRawOption('title',"'$text'");
}
function set3D($x) {
if ($x==true) {
$this->setRawOption('is3D','true');
} else {
$this->setRawOption('is3D','false');
}
}
function setLegend($pos) {
if ($pos==='right' || $pos==='left' || $pos==='top' || $pos==='bottom' || $pos==='none') {
$this->setRawOption('legend',"'$pos'");
} else {
$this->error("Unknown legend position - $pos");
}
}
function setWidth($width) {
$this->setRawOption('width',$width);
}
function setHeight($height) {
$this->setRawOption('height',$height);
}
function rowDatatype($column,$data) {
$datatype = $this->columns[$column][1];
switch($datatype) {
case "string":
return "'$data'";
break;
case "number":
return "$data";
break;
case "boolean":
if ($data==0) {
return "false";
} else {
return "true";
}
break;
case "date":
if (substr_count($data,'-') > 0) {
list($y,$m,$d)=explode("-",$data);
} else {
list($d,$m,$y)=explode("-",date("j-m-Y",$data));
}
return "new Date($y, $m, $d)";
break;
}
}
function output($div='chart_div',$width=400,$height=240) {
echo "\n";
echo "\n";
}
function error($text) {
die("googlevis.class.php :: $text\n");
}
}
?>