PHP Functions for column graphs
Keywords: PHP
#为了方便起见, I made a function to make a column chart.
/* Parameter Description:
$graphdata: Percent 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 values
$grid: Edge Color values
$bar: The color value of the bar
$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 < $graphheight; $i + = $graphheight/10)
{
Imagedashedline ($image, 0, $i, $graphwidth-1, $i, $gridcolor);
Imagestring ($image, $graphfont, 0, $i, round (($graphheight-$i)/$graphscale), $textcolor);
}
$barwidth = (($graphwidth-$gridlabelwidth)/count ($graphdata)) -30;#¿øöæöùµäxü¿í¶è
for ($i =0; $i {
$BARTOPX = $gridlabelwidth + (($i + 1) *20) + ($i * $barwidth); #¿øöæöù¿¿xóµä¾ààë
$BARBOTTOMX = $bartopx + $barwidth;
$barbottomy = $graphheight -1;#¿øöæöùµäïâ±ß½ç
$bartopy = $barbottomy-($graphdata [$i]* $graphscale);
Imagefilledrectangle ($image, $bartopx, $bartopy, $barbottomx, $barbottomy, $barcolor);
$labelx 1= $bartopx;
$labely 1= $bartopy-15;
$labelx 2= $bartopx;
$labely 2= $graphheight;
Imagestring ($image, $graphfont, $labelx 1, $labely 1, "$graphdata [$i]". " % ", $textcolor);
Imagestring ($image, $graphfont, $labelx 2, $labely 2, "$label [$i]", $textcolor);
Imagestringup ($image, $graphfont, $labelx 1+10, $labely 1-$gridableheight, "$data [$i]", $textcolor);
}
Imagestring ($image, $graphfont, 1, $graphheight +30, $BZ, $textcolor);
Imagegif ($image);
}
?>
http://www.bkjia.com/PHPjc/532264.html www.bkjia.com true http://www.bkjia.com/PHPjc/532264.html techarticle PHP to do column chart function keywords: php #为了方便起见, I made a function to make a column chart//Parameter description: $graphdata: Percent data (Y-axis) $label: X-axis title $data ...