Home > Backend Development > PHP Tutorial > PHP function to make column chart_PHP tutorial

PHP function to make column chart_PHP tutorial

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-07-13 17:23:01
Original
905 people have browsed it

PHP function for making column charts

Keywords: PHP

#For the sake of convenience, I made another function to make column charts
/*Parameter description:
$graphdata: Percentage data (y-axis)
$label: x-axis title
$data: Actual data (y-axis)
$graphwidth: Image width
$graphheight: Image height
$ graphscale: height factor (for $graphheight/100)
$graphfont: font number
$bg; background color value
$text: text color value
$grid: edge color value
$ bar: Color value of column
$bz: Remarks (Chinese is not supported)
*/
function timage(
$graphdata,$label,$data,
$graphwidth,$graphheight ,$graphscale,$graphfont,
$bg,$text,$grid,$bar,$bz)
{

header("Content-type:image/gif");
$image=imagecreate($graphwidth+50,$graphheight+50);
$bgcolor= imagecolorallocate ($image,$bg[0],$bg[1],$bg[2]);
$textcolor= imagecolorallocate ($image ,$text[0],$text[1],$text[2]);
$gridcolor=imagecolorallocate ($image ,$grid[0],$grid[1], $grid[2]);
$barcolor=imagecolorallocate ($image,$bar[0],$bar[1],$bar[2]);
$gridabelwidth=imagefontwidth($graphfont)*3 +1;
$gridableheight= imagefontheight ($graphfont);


imageline($image,$gridlabelwidth,0,$gridlabelwidth,$graphheight-1,$gridcolor);
imageline($image ,0,$graphheight-1,$graphwidth-1,$graphheight-1,$gridcolor);
for($i=0;$i{
imagedashedline ($image,0,$i,$graphwidth-1,$i,$gridcolor);
imagestring($image,$graphfont,0,$i,round(($graphheight-$i) /$graphscale),$textcolor);
}

$barwidth=(($graphwidth-$gridlabelwidth)/count($graphdata))-30;#¿ ØÖÆÖùµÄ×Ü¿ í¶È
for($i=0;$i {
$bartopx=$gridlabelwidth+(($i+1)*20)+($i*$barwidth);#¿ØÖÆÖù¿¿×óµÄ¾àÀë
$barbottomx=$bartopx+$barwidth;
$barbottomy=$graphheight-1;#¿ ØÖÆÖùµÄϱ߽ç
$bartopy=$barbottomy-($graphdata[$i]*$graphscale);
imagefilledrectangle($image,$bartopx,$bartopy,$barbottomx,$barbottomy,$barcolor);
$labelx1=$bartopx;
$labely1=$bartopy-15;
$labelx2=$bartopx ;
$labely2=$graphheight;
imagestring($image,$graphfont,$labelx1,$labely1,"$graphdata[$i]"."%",$textcolor);
imagestring($ image,$graphfont,$labelx2,$labely2,"$label[$i]",$textcolor);
imagestringup ($image,$graphfont,$labelx1+10,$labely1-$gridableheight,"$data[ $i]",$textcolor);
}
imagestring($image,$graphfont,1,$graphheight+30,$bz,$textcolor);
imagegif ($image);

}
?>

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/532264.htmlTechArticlePHP function keywords for making column charts: PHP #For the sake of convenience, I made another function to make it Column chart/*Parameter description: $graphdata: percentage data (y-axis) $label: x-axis title $data...
Related labels:
Statement of this Website
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
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template