文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php做柱型图的函数

php做柱型图的函数

时间:2007-02-17  来源:PHP爱好者

#为了方便起见,我又做了一个函数来制作柱型图
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
/*参数说明:
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$graphdata:百分比数据(y轴)
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$label:x轴标题
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$data:实际数据(y轴)
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$graphwidth:图像宽度
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$graph背景颜色值
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$text:文本颜色值
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$grid:边线颜色值
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$bar:柱的颜色值
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$bz:备注(不支持中文呀)
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
*/
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
<?
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
function timage(
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$graphdata,$label,$data,
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$graphwidth,$graphheight,$graphscale,$graphfont,
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$bg,$text,$grid,$bar,$bz)
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
{
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l

www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
header("Content-type:image/gif");
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$image=imagecreate($graphwidth+50,$graphheight+50);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$bgcolor= imagecolorallocate ($image ,$bg[0],$bg[1],$bg[2]);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$textcolor= imagecolorallocate ($image ,$text[0],$text[1],$text[2]);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$gridcolor=imagecolorallocate ($image ,$grid[0],$grid[1],$grid[2]);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$barcolor=imagecolorallocate ($image ,$bar[0],$bar[1],$bar[2]);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$gridabelwidth=imagefontwidth($graphfont)*3+1;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$gridableheight= imagefontheight ($graphfont);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imageline($image,$gridlabelwidth,0,$gridlabelwidth,$graphheight-1,$gridcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imageline($image,0,$graphheight-1,$graphwidth-1,$graphheight-1,$gridcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
for($i=0;$i<$graphheight;$i+=$graphheight/10)
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
{
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagedashedline ($image,0,$i,$graphwidth-1,$i,$gridcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagestring($image,$graphfont,0,$i,round(($graphheight-$i)/$graphscale),$textcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
}
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l

www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$barwidth=(($graphwidth-$gridlabelwidth)/count($graphdata))-30;#&iquest;&Oslash;&Ouml;&AElig;&Ouml;ù&micro;&Auml;×&Uuml;&iquest;í&para;&Egrave;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
for($i=0;$i<count($graphdata);$i++)
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
{
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$bartopx=$gridlabelwidth+(($i+1)*20)+($i*$barwidth);#&iquest;&Oslash;&Ouml;&AElig;&Ouml;ù&iquest;&iquest;×ó&micro;&Auml;&frac34;à&Agrave;&euml;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$barbottomx=$bartopx+$barwidth;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$barbottomy=$graphheight-1;#&iquest;&Oslash;&Ouml;&AElig;&Ouml;ù&micro;&Auml;&Iuml;&Acirc;±&szlig;&frac12;&ccedil;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$bartopy=$barbottomy-($graphdata[$i]*$graphscale);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagefilledrectangle($image,$bartopx,$bartopy,$barbottomx,$barbottomy,$barcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$labelx1=$bartopx;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$labely1=$bartopy-15;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$labelx2=$bartopx;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
$labely2=$graphheight;
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagestring($image,$graphfont,$labelx1,$labely1,"$graphdata[$i]"."%",$textcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagestring($image,$graphfont,$labelx2,$labely2,"$label[$i]",$textcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagestringup ($image,$graphfont,$labelx1+10,$labely1-$gridableheight,"$data[$i]",$textcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
}
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagestring($image,$graphfont,1,$graphheight+30,$bz,$textcolor);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
imagegif ($image);
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l

www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
}
www.chinaitpower.comB2e36CiXvLlA0Ov3MScbB0E6l
?>
php爱好者站 http://www.phpfans.net php动态|php基础|php进阶|php模板.
相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载