|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
小试一下身手,大概是没问题了,那么交给你个任务,做个留言本吧,这和HELLO WORLD有一比啊!^_^,同是新手面临的第一道关。饼图|函数 php做饼图的函数
作者:qdlover 宣布日期:2000年9月15日 浏览次数:14
--------------------------------------------------------------------------------
再引见一下我本人,呵呵
我是个老手,事先学php地道是为了敷衍向导哦,让咱们做统计图,我原本是学asp的,俄然转业很不顺应,不外php功效切实其实很壮大呀,呵呵,我都离不了他了,这不,饼图,柱型图都弄定了,可是还有良多成绩我不会,还但愿人人多指教呀,说了很多多少空话了,我还觉得是在写信那
我的接洽体例是:
email:qingdaohb@yeah.net
http://qdlover.yeah.net
老板催了,没举措,饼图函数出炉了,人人快抢呀
########
bimage.php3
########
<?
/*
函数申明
$chartdata:数据,是数组元素
$chartfont:字号
$chartdiameter:决意饼的巨细(要看你饿不饿了,呵呵)
$chartlabel:题目,也是数组元素
$colorslice:色彩数组,例如$tmp=array255,255,255);$colorslic=array($tmp);
$colorborder:边框色彩,数组
$colortext :文本色彩,数组
$colorbody:后台色彩,数组
$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));
}
?>
###########
这是一个挪用的例子
###########
<?
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 )
?>
【奥索网版权一切,如需转载,请注明出处】
既然选择了PHP,就要坚持学下去!大家有没有问自己为什么会选择学习PHP呢?就我个人而言,完全是因为兴趣,因为我的专业和计算机完全无关,但是就是对编程很赶兴趣,尤其对网络编程、web开发特别赶兴趣。 |
|