程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> php繪制柱型圖的函數代碼

php繪制柱型圖的函數代碼

編輯:關於PHP編程

下面我們來看看關於php繪制柱型圖的函數代碼吧,好費話不說多了來看看吧,好了費話不說多了。  

下面我們來看看關於php繪制柱型圖的函數代碼吧,好費話不說多了來看看吧,好了費話不說多了。

php做柱型圖的函數

關鍵詞:PHP

#為了方便起見,我又做了一個函數來制作柱型圖
/*參數說明:
$graphdata:百分比數據(y軸)
$label:x軸標題
$data:實際數據(y軸)
$graphwidth:圖像寬度
$graphheight:圖像高度
$graphscale:高度因子(為$graphheight/100)
$graphfont:字體號
$bg;背景顏色值
$text:文本顏色值
$grid:邊線顏色值
$bar:柱的顏色值
$bz:備注(不支持中文呀)
*/
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;#¿ØÖÆÖùµÄ×Ü¿í¶È
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);

}
?>


  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved