一个生成动态柱状统计图的函数
时间:2006-01-12 来源:wleige
$color_back=imagecolorallocate($image,0,0,0);
$color_table=imagecolorallocate($image,188,188,188);
$color_pole_b=imagecolorallocate($image,204,0,255);
$color_pole_f=imagecolorallocate($image,152,0,188);
$color_pole_s=imagecolorallocate($image,231,132,255);
$color_text=imagecolorallocate($image,255,217,38);
//配置颜色
imagefilledrectangle($image,0,0,$img_w_t,$img_h_t,$color_back);
//填充背景
$style=array($color_table,$color_table,$color_back,$color_back,$color_back,$color_back);
imagesetstyle($image, $style);
for($i=0;$i
for ($i=0;$i
$len=strlen($score[$i]);
$p_x=($i*$per_w)+$per_w+($per_w-$len*5-3)/2;
//使成绩在立柱中间
imagestring($image,2,ceil($p_x),$img_h-$score[$i]/$per_p-1.6*$per_h,$score[$i],$color_text);
//写入成绩在柱状图上方
}
for($i=0;$i
imagettftext($image,9,270,$per_w*($i+2)-$per_w/2-8,$img_h+5,$color_table,"c:/windows/fonts/simkai.ttf",$str);
}
imagepng($image);
imagedestroy($image);
}
//数组score存放分数,数组name存放该分数对应的名字,数组名可任意取
$score=array(20,33,88,47,11,143,75,117,43);
$name=array("一系","二系","三系","四系","五系","六系","七系","八系","九系");
$j=count($name);
for($i=0;$i
create_img($score,$name);
//调用上面自定义的函数,后面的参数使用了默认值
?>
相关阅读 更多 +