Hi! I want to graph some data from a BD. I have a code but doesn't function. When I call the page, only appears a x. Couldo u check my code???? this code only generate a rectangle with a title, but I can't see it. Thanks!!!
header ("Content-type: image/png");
$width = 480;
$height = 250;
$im = imagecreate($width, $height);
$white = imagecolorallocate ($im,255,255,255);
$blue = imagecolorallocate ($im,0,0,255);
$black = imagecolorallocate ($im, 0, 0, 0);
$red = imagecolorallocate ($im, 255, 0, 0);
$link = mysql_connect("localhost","root","");
mysql_select_db("sorteo", $link);
$res=mysql_query("SELECT COUNT(sexo) FROM registros WHERE sexo='1'", $link);
$row=@mysql_fetch_array($res);
//echo $row[0];
$m=$row[0]; //Cuantas mujeres
$res1=mysql_query("SELECT COUNT(sexo) FROM registros WHERE sexo='2'", $link);
$row1=@mysql_fetch_array($res1);
//echo $row1[0];
$h=$row1[0]; //Cuantos hombres
$numrow=$m+$h; //Llamadas totales
//echo $numrow;
$nval = 2;
$maxval = $numrow;
$vmargin = 20; //Arriba (margen vertical) para el titulo lado x
$hmargin = 38; // izq (margen horizontal) para los datos lado y
$base = floor (($width - $hmargin) / $nval); //distancia entre columnas
$ysize = $height - 2 * $vmargin; //tamaño de y
$xsize = $nval * $base; //tamaño de x
imagerectangle ($im, $hmargin, $vmargin, $hmargin + $xsize, $vmargin + $ysize, $black); //tamaño del recuadro
$titlefont = 3;
$title = "Por Sexo";
$txtsz = imagefontwidth($titlefont) * strlen($title);
$xpos = (int)($hmargin + ($xsize - $txtsz)/2); //centrar el titulo
$xpos = max(1, $xpos); //coordenadas positivas
$ypos = 3; //margen de arriba
imagestring ($im, $titlefont, $xpos, $ypos, $title, $black);
imagepng($im);
imagedestroy($im);