用PHP制作饼图调查表
http://www.people.com.cn/GB/channel5/569/20000623/115761.html
http://www.people.com.cn/GB/channel5/569/20000623/115761.html
解决方案 »
- cookie中的sessionID字段的大小写是否可以配置?
- 实现一个类似于QQ(离开)状态的功能
- 如何让数据按default=?时输出
- php连接mysql的问题
- 如何用post方式向服务器发送数据
- 请教各位一个关于 ajax 的问题 顺便问一下有没有好的支持 php 和msql 的免费空间可以用 国外的也行
- phpArticle2.1 正式发布
- win2003 ii6 升级php5.4.14
- stream_socket_client调用第三方tls服务报错Error为空
- windows下file_uploaded_file权限问题
- 关于exec()函数在Windows下的使用,如何使用文本文件????
- iis+php安装错误,十万火急
Header( "Content-Type:image/gif");
/////////////////////////////////////////////////////////////////////////////////////////
//
// 程序名: Pollbiscuit
//
// 描 述: 这是一个很小的画贺饼图的程序
//
// 数 组: $Biscuit_val 包含了 Biscuit_values 的百分比。
// 数 组: $Biscuit_content 涉及了真正问题的答案。
// 测 试:
// test_biscuit.php3:
// <html><body>
// <h1>Poll result!</h1>
// $Biscuit_val[]=99.96;$Biscuit_content[]="I donn't know!";
// $Biscuit_val[]=0.01; $Biscuit_content[]="I think so";
// $Biscuit_val[]=0.01; $Biscuit_content[]="NO,just a joke";
// $Biscuit_val[]=0.01; $Biscuit_content[]="Like it";
// <Img src=PollBiscuit.php3?<script language="php"> for($i=0;$i<count($Biscuit_val);$i++) echo "Biscuit_val[$i]=$Biscuit_val[$i]"."&"."content[$i]=\
// ".urlencode($Biscuit_content[$i])."&"; </script> border=0 >
// </body></html>
$num=count($Biscuit_val); //////////////////////// 作图区定义 /////////////////////////////////////////
$img_w=300; //图片的宽
$img_h=130; //图片的高
$bottom=10; //矩形的下坐标
$left=120; //矩形的左坐标
$a=100; //椭圆的长轴
$b=50; //椭圆的短轴
$distance=10; //矩形间的距离
$id=ImageCreate($img_w,$img_h); //创建画图区(画布)///////////////////////// 颜色定义 ///////////////////////////////////////// $black=ImageColorAllocate($id,0,0,0);
$white=ImageColorAllocate($id,255,255,255);
$color[]=ImageColorAllocate($id,0,255,0);
$color[]=ImageColorAllocate($id,255,0,0);
$color[]=ImageColorAllocate($id,0,0,255);
$color[]=ImageColorAllocate($id,255,255,0);
$color[]=Imagecolorallocate($id,0,255,255);
$color[]=Imagecolorallocate($id,255,0,255);
$color[]=Imagecolorallocate($id,125,125,125);
$color[]=Imagecolorallocate($id,0,0,125);
$color[]=Imagecolorallocate($id,125,0,0);
$color[]=Imagecolorallocate($id,0,0,125);
$color[]=Imagecolorallocate($id,125,125,0);
$color[]=Imagecolorallocate($id,0,125,125);
$red=$color[1];
$green=$color[0];
$blue=$color[2];
$yellow=$color[3];
$trans=ImageColorTransparent($id,$white); //透明的颜色定义
ImageFill($id,0,0,$white); //填充透明的颜色
$img_center_x=50; //X坐标轴在图作图区的中央坐标
$img_center_y=$img_h/2; //Y坐标轴在图作图区的中央坐标////////////////////////// 画椭圆 //////////////////////////
ImageArc($id,$img_center_x,$img_center_y,$a,$b,0,360,$black);
ImageArc($id,$img_center_x,$img_center_y+$distance,$a,$b,0,180,$black);
imageline($id,$img_center_x,$img_center_y,$img_center_x+$a/2,$img_center_y,$black); ///////////////////////// 画线 //////////////////////// Imageline($id,$img_center_x+$a/2,$img_center_y,$img_center_x+$a/2,$img_center_y+$distance,$black);
Imageline($id,$img_center_x-$a/2,$img_center_y,$img_center_x-$a/2,$img_center_y+$distance,$black); //////////////////////// 画圆饼 ////////////////////////////
$angle1=$angle2=0; //角度angles
for ($i=0;$i<$num;$i++)
{
$angle2=$angle1;
$angle1+=$Biscuit_val[$i]*M_PI*2/100; //计算角度
if ($i!=$num-1)
imageline($id,$img_center_x,$img_center_y,$img_center_x+$a*cos($angle1)/2,$img_center_y-$b*sin($angle1)/2,$black);
imagefill($id,$img_center_x+$a*cos(($angle1+$angle2)/2)/4,$img_center_y-$b*sin(($angle1+$angle2)/2)/4,$color[$i]);
if ($angle1>M_PI)
{
imageline($id,$img_center_x+$a*cos($angle1)/2,$img_center_y-$b*sin($angle1)/2,$img_center_x+$a*cos($angle1)/2,$img_center_y-$b*sin($angle1)/2+$distance,$black);
if ($angle2>=M_PI)
imagefill($id,$img_center_x+$a*cos(($angle1+$angle2)/2)/2,$img_center_y-$b*sin(($angle1+$angle2)/2)/2+$distance/2,$color[$i]);
else
imagefill($id,$img_center_x+$a*cos(($angle1+M_PI)/2)/2,$img_center_y-$b*sin(($angle1+M_PI)/2)/2+$distance/2,$color[$i]);
}
imagefilledrectangle($id,$left,$bottom-5,$left+10,$bottom,$color[$i]);
$string=sprintf( "%.2f",$Biscuit_val[$i]);
$string.= "%". " (".stripslashes($Biscuit_content[$i]). ")";
imagestring($id,2,$left,$bottom-2,$string,$black);
$bottom+=20;
} ImageGif($id);
Imagedestroy($id);