Home >Backend Development >PHP Tutorial >How to use PHP as a function for line graph_PHP Tutorial

How to use PHP as a function for line graph_PHP Tutorial

WBOY
WBOYOriginal
2016-07-20 11:04:59957browse

I'm glad that everyone has such a soft spot for PHP!
The following is an introduction to PHP's function for making line graphs:
/*
Function description
$data: y-axis data (array)
$graphdata: y-axis data--percentage ( Array)
$label:x-axis data (array)
$height:image height
$width:image width
$font:font size
$dot: the size of the decision 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."
";
$x1=(($width-50)/count($data))*($i)+40;
#echo $x1 ."
";
$y1=$height-$graphdata[$i]*$jc;
$x2=$x1;
$y2=$y1+$graphdata[$i]* $jc;
#echo $y1."
";
imagestring($image,$font,$x1,$y1-2*$fontheight,$graphdata[$i]."%(" .$data[$i].")",$text);
imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor);
imagefilltoborder ($image, $x1,$y1,$dotcolor,$dotcolor);
imagestring ($image,$font,$x1,$y2,$label[$i],$text);
if ($i>0 )
{
imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line);
}
$tmpx1=$x1;$tmpy1=$y1;
}
imagegif ($image,$file);
}
?>


www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/445170.htmlTechArticleI’m glad that everyone has such a soft spot for PHP! Let me introduce to you the function of making line graph in PHP: /* Function description $data: y-axis data (array) $graphdata: y-axis data--percentage (array...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn