PHP as a line graph function
Keywords: PHP
/*
Function description
$data: Y-axis data (array)
$graphdata: Y-axis data--percent (array)
$label: X-axis data (array)
$height: Image Height
$width: Image width
$font: Font Size
$dot: Determining the size of a point
$BG: Background color
$line: Line Color
$text: Text color
$dotcolor: Dot Color
$file: Output image file name
*/
function Qximage ($data,
$graphdata,
$label,
$height,
$width,
$font,
$dot,
$BG,
$line,
$text,
$dotcolor,
$file)
{
$JC = $height/100;
$fontwidth = Imagefontwidth ($font);
$fontheight =imagefontheight ($font);
$image = Imagecreate ($width, $height +20);
$BG = Imagecolorallocate ($image, $BG [0], $BG [1], $BG [2]);
$line =imagecolorallocate ($image, $line [0], $line [1], $line [2]);
$text =imagecolorallocate ($image, $text [0], $text [1], $text [2]);
$dotcolor =imagecolorallocate ($image, $dotcolor [0], $dotcolor [1],$ $dotcolor [2]);
Imageline ($image, 0,0,0, $height, $line);
Imageline ($image, 0, $height, $width, $height, $line);
for ($i =1; $i <11; $i + +)
{
Imagedashedline ($image, 0, $height-$JC * $i *10, $width, $height-$JC * $i *10, $line);
Imagestring ($image, $font, 0, $height-$JC * $i *10, $i *10, $text);
}
for ($i =0; $i {
#echo $tmp. "
";
$x 1= (($width -50)/count ($data)) * ($i) +40;
#echo $x 1. "
";
$y 1= $height-$graphdata [$i]* $JC;
$x 2= $x 1;
$y 2= $y 1+ $graphdata [$i]* $JC;
#echo $y 1. "
";
Imagestring ($image, $font, $x 1, $y 1-2* $fontheight, $graphdata [$i]. "% (". $data [$i]. ")", $text);
Imagearc ($image, $x 1, $y 1, $dot, $dot, 0,360, $dotcolor);
Imagefilltoborder ($image, $x 1, $y 1, $dotcolor, $dotcolor);
Imagestring ($image, $font, $x 1, $y 2, $label [$i], $text);
if ($i >0)
{
Imageline ($image, $tmpx 1, $tmpy 1, $x 1, $y 1, $line);
}
$TMPX 1= $x 1; $tmpy 1= $y 1;
}
Imagegif ($image, $file);
}
?>
http://www.bkjia.com/PHPjc/532262.html www.bkjia.com true http://www.bkjia.com/PHPjc/532262.html techarticle PHP function for line graph keywords: PHP/* Function Description $data: Y-axis data (array) $graphdata: Y-axis data--percent (array) $label: X-axis data (array) $height: Image Height ...