首 页   · 站长博客 · 用户注册 · 会员登陆  · 会员排行  ·最新主题  ·最近回复  精华区  版权声明  ·论坛管理
  当前登录身份:游客,请先登录。  笔名: 口令: 验证码:   
楼 主  index »  PHP与模板与代码加密/优化 » [转帖]圆饼图程序  


  作者:pnrj7999
  注册时间:2005-04-04
  主题/回复:73/43
  积分:813
  等级:★★★(六级)
  称号:声名鹊起

用户联系方式已设置为保密

 

 发表:2005-04-26 01:06:12 阅读 2116 次 回复 0 次 得分0  |   字号 字色
[转帖]圆饼图程序
<? 
    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> 
//    程序更改日志: 
// 日期    作者姓名    备注  
// ----------- ----------- ------------------------------------------------  
//  4/14/2000    Mouse Chen( litmouse@km169.net   )    Translate to Chinese
//  3/25/2000    Chriss lee( chriss.lee@sohu.com  ) Created 

///////////////////////////////////////////////////////////////////////////////////////// 


    
    $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); 

?> 
 
  页数1/1首页 « 1 » 末页
  发表回复:您还没有登陆,无法发表回复。请先[登陆]

一起PHP技术联盟 主办:一起PHP 联系方式:站长QQ:4304410 QQ群:8423742 20159565 站长博客 E-mail: nqp@nqp.me 执行时间:0.009sec
SimsmaBBS 2008 (v6.0) Developed by 17php.com,Copyright(C)2003-2010 All rights reserved. 副本授权:一起PHP官方专用版