喜悦国际村 
» 游客:  注册 | 登录 | 搜索 | 统计 | 帮助

RSS 订阅当前论坛  

喜悦证交所已经关闭

上一主题 下一主题
     
标题: 一个动态生成的条型图片  
 
liexusong
新手上路
Rank: 1



UID 89192
精华 0
积分 40
帖子 20
金钱 40 喜悦币
威望 0
人脉 0
阅读权限 10
注册 2007-3-11
状态 离线
一个动态生成的条型图片

<?
//设置图片基本属性
$GraphWidth = 400;
$GraphHeight = 200;
$GraphScale = 2;
$GraphFont = 5;
$GraphData = array("99","75","15","66","22");
$GraphLabel = array("Beef","Chicken","Pork","Lamb","Lobster");

//create image
$image = imagecreate($GraphWidth,$GraphHeight);

//allocate colors
$colorBody = imagecolorallocate($image,111,111,111);
$colorGrid = imagecolorallocate($image,222,222,222);
$colorBar = imagecolorallocate($image,123,123,123);
$colorText = imagecolorallocate($image,32,121,42);

//fill background
imagefill($image,0,0,$colorBody);

//draw vertical grid line
$GridLabelWidth = imagefontwidth($GraphFont) * 3 + 1;
imageline($image,$GridLabelWidth,0,$GridLabelWidth,$GraphHeight-1,$colorGrid);

//draw horizontal grid lines
        for($index = 0 ; $index < $GraphHeight ; $index += $GrapgHeight / 10)
        {
                imagedashedline($image,0,$index,$GraphWidth - 1,$index,$colorGrid);
               
                //draw label
                imagestring($image,$GraphFont,0,$index,round(($GraphHeight - $index)/$GraphScale),$colorText);
               
        }
       
//add bottom line
imageline($image,0,$GraphHeight -1,$GraphWidth - 1,$GraphHeight - 1,$colorGrid);

//draw each bar
$BarWidth = (($GraphWidth - $GridLabelWidth)/count($GraphData)) - 10;

for($index = 0 ; $index < count($GraphData);$index++){
        //draw bar
        $BarTopX = $GridLabelWidth +( ($index + 1) * 10)+ ($index * $BarWidth);
        $BarBottomX = $BarTopX + $BarWidth;
        $BarBottomY = $GraphHeight -1;
        $BarTopY = $BarBottomY - ($GraphData[$index] * $GraphScale);
        imagefilledrectangle($image,$BarTopX,$BarTopY,$BarBottomX,$BarBottomY,$colorBar);
       
        //draw label
        $LabelX = $BarTopX + (($BarBottomX - $BarTopX)/2) - (imagefontheight($GraphFont)/2);
        $LabelY = $BarBottomY - 10;
        imagestringup($image,$GraphFont,$LabelX,$LabelY,"$GraphLabel[$index] : $GraphData[$index]",$colorText);
        }       

//output image
header("content-type:image/png");
imagepng($image);
?>
2007-3-13 04:42 PM#1
查看资料  发短消息  顶部
     


  可打印版本 | 推荐给朋友 | 订阅主题 | 收藏主题 | 开通个人空间  


 




Powered by Discuz! 6.1.0  © 2001-2010 Comsenz Inc.
Processed in 0.024848 second(s), 6 queries

(冀ICP备05009913号) 管理员:sadly 邮箱/MSN: sadly@phpx.com QQ:824008(长隐) 清除 Cookies - - Archiver - WAP