function getGraph
($tot_width =
90,
$tot_height =
100,
$path =
'extras/')
{
$x_offset =
25;
$filename =
$path.
'stats_'.
date('YmdH').
'.png';
if(!
file_exists($filename))
{
$im = imagecreate
($tot_width+
$x_offset,
$tot_height);
//Colores
$color_bkg = imagecolorallocate($im,$this->color_background['red'],$this->color_background['green'], $this->color_background['blue']);
$color_days = imagecolorallocate($im,$this->color_days['red'], $this->color_days['green'], $this->color_days['blue']);
$color_hits = imagecolorallocate($im,$this->color_hits['red'], $this->color_hits['green'], $this->color_hits['blue']);
$color_percent = imagecolorallocate($im,$this->color_percents['red'], $this->color_percents['green'], $this->color_percents['blue']);
$color_bars = imagecolorallocate($im,$this->color_bars['red'], $this->color_bars['green'], $this->color_bars['blue']);
$color_dashedline = imagecolorallocate($im,$this->color_dashedline['red'], $this->color_dashedline['green'], $this->color_dashedline['blue']);
$color_titles = imagecolorallocate($im,$this->color_titles['red'], $this->color_titles['green'], $this->color_titles['blue']);
imagefill($im,0,0,$color_bkg); //El color de fondo del gráfico
imagedashedline($im,10+$x_offset,10,10+$x_offset,$tot_height-8,$color_dashedline);
imagestring($im,1,8+$x_offset,$tot_height-7,'0%',$color_percent); //Lo que aparece como: 0%
imagedashedline($im,35+$x_offset,10,35+$x_offset,$tot_height-8,$color_dashedline);
imagestring($im,1,32+$x_offset,$tot_height-7,'50%',$color_percent); //Lo que aparece como: 50%
imagedashedline($im,60+$x_offset,10,60+$x_offset,$tot_height-8,$color_dashedline);
imagestring($im,1,54+$x_offset,$tot_height-7,'100%',$color_percent); //Lo que aparece como: 100%
imagestring($im,1,0+$x_offset,0,'Día',$color_titles); //Dibujamos el texto Día
imagestring($im,1,50+$x_offset,0,'Visitas',$color_titles); //dibujamos el texto Visitas
$y1 = $y1+10;
$y2 = $y2+10;
//$total_week_hits = $this->getTotalWeekHits();
//$anum = $total_week_hits['hits'];
$max_week_hits = $this->getMaxWeekHits();
$bnum = "0$max_week_hits";
//Ahora empezamos a dibujar las barras de los gráficos
foreach($this->week_hits as $day_hits)
{
$var = $day_hits['unique']/$bnum*100;
$width = $var/2;
$y1 = $y1+10;
$y2 = $y1+8;
$date = explode('/',$day_hits['when']);
if($y1<$tot_height-12)
{
imagestring($im,1,0,$y1,$this->daychar[$date[3]].' '.$date[0].'/'.$date[1],$color_days); //Día correspondiente a las visitas
imagerectangle($im,10+$x_offset,$y1,$width+8+$x_offset,$y2,$color_bars);
imagestring($im,1,65+$x_offset,$y1,$day_hits['unique'],$color_hits); //Numero de visitas
imagefilledrectangle($im,11+$x_offset,$y1+1,$width+9+$x_offset,$y2-1,$color_bars);
}
}
//Guardamos la imagen donde queramos
imagepng($im,$filename);
//eliminamos la anterior;
$this->deleteLastImage($path);
}
return 'http://'.$_SERVER['HTTP_HOST'].'/'.$filename;
}
Escribe un Comentario