php做餅圖的函數(shù)(轉(zhuǎn))
發(fā)表時(shí)間:2023-08-05 來(lái)源:明輝站整理相關(guān)軟件相關(guān)文章人氣:
[摘要]php做餅圖的函數(shù)作者:qdlover 發(fā)表日期:2000年9月15日 閱讀次數(shù):14--------------------------------------------------------...
php做餅圖的函數(shù)
作者:qdlover 發(fā)表日期:2000年9月15日 閱讀次數(shù):14
--------------------------------------------------------------------------------
再介紹一下我自己,呵呵
我是個(gè)新手,當(dāng)時(shí)學(xué)php純粹是為了應(yīng)付領(lǐng)導(dǎo)哦,讓我們做統(tǒng)計(jì)圖,我本來(lái)是學(xué)asp的,突然改行很不適應(yīng),不過(guò)php功能的確很強(qiáng)大呀,呵呵,我都離不了他了,這不,餅圖,柱型圖都搞定了,可是還有很多問(wèn)題我不會(huì),還希望大家多指教呀,說(shuō)了好多廢話了,我還以為是在寫(xiě)信那
我的聯(lián)系方式是:
email:qingdaohb@yeah.net
http://qdlover.yeah.net
老板催了,沒(méi)辦法,餅圖函數(shù)出爐了,大家快搶呀
########
bimage.php3
########
<?
/*
函數(shù)說(shuō)明
$chartdata:數(shù)據(jù),是數(shù)組元素
$chartfont:字號(hào)
$chartdiameter:決定餅的大小(要看你餓不餓了,呵呵)
$chartlabel:標(biāo)題,也是數(shù)組元素
$colorslice:顏色數(shù)組,例如$tmp=array255,255,255);$colorslic=array($tmp);
$colorborder:邊框顏色,數(shù)組
$colortext :文本顏色,數(shù)組
$colorbody:背景顏色,數(shù)組
$file:輸出圖片文件名*/
function bimage($chartdata,
$chartfont,
$chartdiameter ,
$chartlabel ,
$colorslice,
$colorbody ,
$colorborder,
$colortext ,
$file
)
{
$chartdiameter=150;
$chartfontheight=imagefontheight($chartfont);
$d1=10;$d2=20;$d3=30;$d4=40;$d5=50;
$chartdata=array($d1,$d2,$d3,$d4,$d5);
$chartlabel=array("D1","D2","D3","D4","D5");
$chartwidth=$chartdiameter+20;
$chartheight=$chartdiameter+20+(($chartfontheight+2)*count($chartdata));
header("content-type:image/gif");
$image=imagecreate($chartwidth,$chartheight);
$colorbody =imagecolorallocate ($image,$colorbody[0],$colorbody[1],$colorbody[2]);
$colortext =imagecolorallocate ($image,$colortext[0],$colortext[1],$colortext[2]);
$colorborder =imagecolorallocate ($image,$colorborder[0],$colorborder[1],$colorborder[2]);
for ($i=0;$i<count($colorslice);$i++)
{
$t=imagecolorallocate($image,$colorslice[$i][0],$colorslice[$i][1],$colorslice[$i][2]);
$colorslice[$i]=$t;
}
for($i=0;$i<count($chartdata);$i++)
{
$charttotal+=$chartdata[$i];
}
$chartcenterx=$chartdiameter/2+10;
$chartcentery=$chartdiameter/2+10;
$degrees=0;
for($i=0;$i<count($chartdata);$i++)
{
$startdegrees=round($degrees);
$degrees+=(($chartdata[$i]/$charttotal)*360);
$enddegrees=round($degrees);
$currentcolor=$colorslice[$i%(count($colorslice))];
imagearc($image ,
$chartcenterx,
$chartcentery,
$chartdiameter,
$chartdiameter,
$startdegrees,
$enddegrees,
$currentcolor);
list($arcx,$arcy)=circle_point($startdegrees,$chartdiameter);
imageline($image,
$chartcenterx,
$chartcentery,
floor($chartcenterx+$arcx),
floor($chartcentery+$arcy),
$currentcolor );
list($arcx,$arcy)=circle_point($enddegrees,$chartdiameter);
imageline($image,
$chartcenterx,
$chartcentery,
ceil($chartcenterx+$arcx),
ceil($chartcentery +$arcy),
$currentcolor);
$midpoint=round((($enddegrees-$startdegrees)/2)+$startdegrees);
list($arcx,$arcy)= circle_point ( $midpoint, $chartdiameter/2);
imagefilltoborder($image,
floor($chartcenterx+$arcx),
floor($chartcentery+$arcy),
$currentcolor,
$currentcolor);
}
imagearc($image,
$chartcenterx,
$chartcentery,
$chartdiameter,
$chartdiameter,
0,360,
$colorborder);
imagefilltoborder ($image,
floor($chartcenterx +( $chartdiameter /2)+2),
$chartcentery ,
$colorborder,
$colorborder );
for ($i=0;$i<count($chartdata);$i++)
{
$currentcolor=$colorslice[$i%(count($colorslice))];
$liney=$chartdiameter+20+($i*($chartfontheight+2));
imagerectangle ($image,
10,
$liney,
20+$chartfontheight,
$liney+$chartfontheight,
$colorbody);
imagefilltoborder($image,
12,
$liney+2,
$colorbody,
$currentcolor);
imagestring($image,
$chartfont,
40+$chartfontheight,
$liney,
"$chartlabel[$i]:$chartdata[$i]",
$colortext);
}
imagegif ($image,$file);
}
function radians($degrees)
{
return($degrees*(pi()/180.0));
}
function circle_point($degrees,$diameter)
{
$x=cos(radians($degrees))*($diameter/2);
$y=sin(radians($degrees))*($diameter/2);
return (array($x,$y));
}
?>
###########
這是一個(gè)調(diào)用的例子
###########
<?
include("bfunc.php3");
$chartdiameter=250;
$chartfont=5;
$d1=10;$d2=20;$d3=30;$d4=40;$d5=50;
$chartdata=array($d1,$d2,$d3,$d4,$d5);
$chartlabel=array("D1","D2","D3","D4","D5");
$colorbody=array(0xff,0xff,0xff);
$colorborder=array(0x00,0x00,0x00);
$colortext=array(0xff,0xff,0xff);
$color1=array(0xff,0x00,0x00);
$color2=array(0x00,0xff,0x00);
$color3=array(0x00,0x00,0xff);
$color4=array(0xff,0xff,0x00);
$color5=array(0xff,0x00,0xff);
$colorslice=array($color1 ,$color2,$color3,$color4,$color5);
$file="tj.gif"
bimage($chartdata,
$chartfont,
$chartdiameter ,
$chartlabel ,
$colorslice,
$colorbody ,
$colorborder,
$colortext ,
$file )
?>
【奧索網(wǎng)版權(quán)所有,如需轉(zhuǎn)載,請(qǐng)注明出處】