<?php
/*
 *  make the multi-line chart
 */ 
 
// include class file
include('plchart.php'); 


function apc_fetch_udt($key){	
	$udtl_store = apc_fetch("udt".$key);
	$udt = time();
	if ($udtl_store){
		if ($udt-$udtl_store<9) { // 5 segundos maximo de vida
			$val = apc_fetch($key);
			apc_store('dif', ($udt-$udtl_store));
			return $val; 
		} else {
			// no vamos a borrar, es mejor que los datos esten obsoleto a que no este y se caiga.
			/*apc_delete($key);
			apc_delete("udt".$key);*/
			
			return false;
		}
	} else {
		return false;
	}
}
function apc_store_udt($key,$g){
	$udt = time();
	apc_store($key, $g);
	apc_store("udt".$key, $udt);
} 

   
// set the array of source data
// the first array is the descriptions of x coordinate 
$data = apc_fetch("datos_graficos");


$data[0][count($data[0])]=$data[0][count($data[0])-1]+1;
$data["2000"][count($data["2000"])]=rand(0,100);
$data["2001"][count($data["2001"])]=rand(0,100);
$data["2002"][count($data["2002"])]=rand(0,100);
$data["2003"][count($data["2003"])]=rand(0,100);


apc_store("datos_graficos",$data);

// set chart object
$chart = new plchart(); 

//echo var_dump($data["2000"]);
/*
for ($i=0;$i<count($data["2000"]);$i++) {
	$data["2000"][$i]=$data["2000"][$i]*rand();
}
*/
   
// set bgcolor
$chart->setbgcolor(255,255,255);    

// set string for title
$title = <<< string
Grafico
string;
$title="titulo";

// set chartdata

$chart->param_titulo=array('2005','2006','2001','2002');


$chart->setchartdata("line", 1, 800, 600, 100, $data, '');
    
// set title
$chart->settitle($title, 10, 0, 200, 50, 'fonts/arial.ttf', 0, 0, 250);

// set description
$chart->setdesc(650, 100, 100, 300, 0, 10, 0, 'fonts/arial.ttf', 0, 0, 0);
     
// set graphics
$chart->setgraphics(0, 100, 600, 300, 20, 0.05);
    
// output chart
$chart->outputchart();    

// destroy object
unset($chart);
?>