Hi,
The program supposed to allow user to enter 1-10 categories to made the pie chart.
I’m stuck with the problem in my php code, not sure whats the actual problem is but it I think somehow the data didn’t manage to get into PHP code.
here is my PHP code:
[php]
<?php function handleError() { // Redirect browser to error page if anything seems wrong with the // input header("Location: Errors.html"); exit; } //check the data - submitted in two text area form elements // was there any data $cats = $_POST["catlist"]; $vals = $_POST["numlist"]; $title = $_POST["title"]; echo $cats; echo $vals; if(empty($cats) || empty($vals) || empty($title)) { handleError(); } // There was some data. // Supposed to be a series of lines, try splitting on newline $categories = split("\n", $cats); $values = split("\n",$vals); // The number of numeric values must equal the number of // category values $numc = count($categories); $numv = count($value); if($numc != $numv) { handleError(); } if(($numc<1) || ($numc>10)) { handleError(); } // Check the values // Use regex checks $numpat = '/^[0-9]+\.?[0-9]*$/'; $catpat = '/^[A-Za-z0-9 ]+$/'; for($i=0;$i<$numc;$i++) { $tmpc = rtrim($categories[$i]); $tmpv = rtrim($values[$i]); if(!preg_match($catpat,$tmpc)) { handleError(); } if(!preg_match($numpat,$tmpv)) { handleError(); } } $titlepat = '/^[A-Za-z0-9,; ]+$/'; if(!preg_match($titlepat,$title)) { handleError(); } // data look ok // echo "Data ok"; echo $cats; echo $vals; //header("Content-type: image/png"); $width = 1000; $height = 700; $im = imagecreate($width, $height); $white = imagecolorallocate ($im, 255, 255, 255); $black = imagecolorallocate ($im, 0, 0, 0); $color[] = imagecolorallocate ($im, 0, 255, 255);//cyan $color[] = imagecolorallocate ($im, 0, 0, 255);//blue $color[] = imagecolorallocate ($im, 255, 0, 255);//fuschia $color[] = imagecolorallocate ($im, 0, 128, 0);//green $color[] = imagecolorallocate ($im, 0, 255, 0);//lime $color[] = imagecolorallocate ($im, 128, 0, 0);//maroon $color[] = imagecolorallocate ($im, 0, 0, 128);//navy $color[] = imagecolorallocate ($im, 128, 128, 0);//olive $color[] = imagecolorallocate ($im, 128, 0, 128);//purple $color[] = imagecolorallocate ($im, 255, 0, 0);//red // font directory $fontdir = "C:\\Windows\\Fonts\\"; // font try Lucida Bright $font = "LBRITE.TTF"; $fd = $fontdir . $font; $titlex = 10; $titley = 50; $titleangle = 0; $ptsize = 32; imagettftext($im, $ptsize, $titleangle, $titlex, $titley, $black, $fd, $title); //imagepng($im); //imagedestroy($im); // Work out angles for pie graph $total = 0; for($i=0;$numv;$i++) { $tmpv = rtrim($values[$i]); $total += $tmpv; } $angles = array(); for($i=0;$numv;$i++) { $tmpv = rtrim($values[$i]); $anagle = ($tmpv*360)/$total; $angles[] = $anangle; } // Define circle - centre point, width, height $cx = 250; $cy = 250; $cwidth = 255; $cheight = 255; // Draw angles $startangle = 0; for($i=0;$numv;$i++) { $endangle = $startangle + $angles[$i]; $arccolor = $color[$i]; imagefilledarc($im, $cx, $cy, $cwidth, $cheight, $startangle, $endangle, $arccolor, IMG_ARC_PIE); $startangle = $endangle; } // Name table $left = 450; $top = 120; $step = 36; $ptsize = 20; $angle = 0; for($i=0;$numc;$i++) { $str = rtrim($categories[$i]); $txtcolor = $color[$i]; imagettftext($im, $ptsize, $angle, $left, $top, $txtcolor, $fd, $str); $top += $step; } header("Content-type: image/png"); imagepng($im); imagedestroy($im); ?>[/php]