Page 1 of 1

PHP Graph Script bug

Posted: Mon Jul 14, 2008 11:26 am
by ferquetzal
Hi, my problem is that I´m testing the following script to graph some data. It works good, but if one of the elements is a zero, it doesn´t work. Data is taken from other script and sent by the following sentence:

***************
$dat = implode (',', $el_array);
echo "<img src='graphpastel.php?dat=$dat&bkg=FFFFFF&wdt=250&h gt=100'>";

*****************
My question is: how can I remove the zeros from the string? and how can I make transparent the background of the image? Thank you


<?
Header( "Content-type: image/png");
//Header( "Content-type: image/jpeg");
require("grab_globals.lib.php");

if($bkg == "") $bkg="FFFFFF";
if($wdt == "") $wdt=200;
if($hgt == "") $hgt=100;

$por = array();
$dato = array();

foreach ($dato as $valor) {
$total += $dato[$i];
$nvars++;
}

$dato = split(",", str_replace(" ","",$dat));
foreach ($dato as $valor) {
if($valor == null)
unset($array[$valor]);

}
$dat = array_values($dato);
/* crea imagen */
$image = imagecreate($wdt +1,$hgt+21);

// librerias de Colores y Funciones
include('libcolores.php');
include('libfunciones.php');

sscanf($bkg, "%2x%2x%2x", $rr, $gg, $bb);
$colorbkg = ImageColorAllocate($image,$rr,$gg,$bb);

// crea bkg blanco
ImageFilledRectangle($image,0,0,$wdt +1,$hgt+21,$colorbkg);

$nvars = 0;
foreach ($dato as $valor) {
$total += $dato[$i];
$nvars++;
}

for ($i = 0;$i < $nvars;$i++)
$total += $dato[$i];

for ($i = 0;$i < $nvars;$i++)
$por[$i] = ($dato[$i] * 360) / $total;

$inicio = 0;
$final = 0;

for ($j = ($hgt/2)+15;$j > $hgt/2;$j--) {
for ($i = 0, $c = 6;$i < $nvars;$i++,$c+=3) {
$final += $por[$i];
imagefilledarc ($image, $wdt/2, $j, $wdt, $hgt, $inicio, $final, $colores[$c], IMG_ARC_PIE);
$inicio = $final;
}
}

$inicio = 0;
$final = 0;

for ($i = 0, $c = 5;$i < $nvars;$i++, $c+=3) {
$final += $por[$i];
imagefilledarc ($image, $wdt/2, $hgt/2, $wdt, $hgt, $inicio, $final, $colores[$c], IMG_ARC_PIE);
$inicio = $final;
}

/* Realiza la generacion del grafico */

ImagePNG($image);
//ImageJPEG($image,'',100);

/* Vacia la memoria */
ImageDestroy($image);
?>