日期:2013-04-22  浏览次数:20497 次

<?php

 


class GD{
 /*
函数说明
$data:y轴数据(数组)
$graphdata:y轴数据--百分比(数组)
$label:x轴数据(数组)
$height:图像高度
$width:图像宽度
$font:字号
$dot:决定点的大小
$bg:背景色
$line :线色
$text :文本色
$dotcolor:点色
$file:输出图像文件名
*/
//线形图的函数
function qximage($data , $graphdata, $label , $height, $width , $font, $dot, $bg, $line, $text, $dotcolor, $file)
{
$jc=$height/100;
$fontwidth= imagefontwidth ($font);
$fontheight=imagefontheight($font);

$image= imagecreate ($width,$height+20);
$bg= imagecolorallocate($image ,$bg[0],$bg[1],$bg[2]);
$line=imagecolorallocate($image ,$line[0],$line[1],$line[2]);
$text=imagecolorallocate($image ,$text[0],$text[1],$text[2]);
$dotcolor=imagecolorallocate($image ,$dotcolor[0],$dotcolor[1],$$dotcolor[2]);
imageline ($image,0,0,0,$height,$line);
imageline($image,0,$height,$width,$height,$line);
for ($i=1;$i<11;$i++)
{
 imagedashedline($image,0,$height - $jc*$i*10 ,$width ,$height -$jc*$i*10 ,$line );
 imagestring ($image,$font,0,$height-$jc*$i*10,$i*10,$text);
}
for ($i=0;$i {
 #echo $tmp." ";
 $x1=(($width-50)/count($data))*($i)+40;
 #echo $x1 ." ";
 $y1=$height-$graphdata[$i]*$jc;
 $x2=$x1;
 $y2=$y1+$graphdata[$i]*$jc;
 #echo $y1." ";
 imagestring($image,$font,$x1,$y1-2*$fontheight,$graphdata[$i]."%(".$data[$i].")",$text);
 imagearc ($image,$x1 ,$y1,$dot,$dot,0,360,$dotcolor);
 imagefilltoborder ($image,$x1,$y1,$dotcolor,$dotcolor);
 imagestring ($image,$font,$x1,$y2,$label[$i],$text);
 if ($i>0)
 {
  imageline($image,$tmpx1,$tmpy1,$x1,$y1,$line);
 }
 $tmpx1=$x1;$tmpy1=$y1;
}
imagegif ($image,$file);
}
//为了方便起见,我又做了一个函数来制作柱型图
/*参数说明:
$graphdata:百分比数据(y轴)
$label:x轴标题
$data:实际数据(y轴)
$graphwidth:图像宽度
$graphheight:图像高度
$graphscale:高度因子(为$graphheight/100)
$graphfont:字体号
$bg;背景颜色值
$text:文本颜色值
$grid:边线颜色值
$bar:柱的颜色值
$bz:备注(不支持中文呀)
*/
 function timage(
 $graphdata,$label,$data,
 $graphwidth,$graphheight,$graphscale,$graphfont,
 $bg,$text,$grid,$bar,$bz)
 {

 header("Content-type:image/gif");
 $image=imagecreate($graphwidth+50,$graphheight+50);
 $bgcolor= imagecolorallocate ($image ,$bg[0],$bg[1],$bg[2]);
 $textcolor= imagecolorallocate ($image ,$text[0],$text[1],$text[2]);
 $gridcolor=imagecolorallocate ($image ,$grid[0],$grid[1],$grid[2]);
 $barcolor=imagecolorallocate ($image ,$bar[0],$bar[1],$bar[2]);
 $gridabelwidth=imagefontwidth($graphfont)*3+1;
 $gridableheight= imagefontheight ($graphfont);
 imageline($image,$gridlabelwidth,0,$gridlabelwidth,$graphheight-1,$gridcolor);
 imageline($image,0,$graphheight-1,$graphwidth-1,$graphheight-1,$gridcolor);
 for($i=0;$i<$graphheight;$i+=$graphheight/10)
 {
  imagedashedline ($image,0,$i,$graphwidth-1,$i,$gridcolor);
  imagestring($image,$graphfont,0,$i,round(($graphheight-$i)/$graphscale),$textcolor);
 }

 $barwidth=(($graphwidth-$gridlabelwidth)/count($graphdata))-30;#¿ØÖÆÖùµÄ×Ü¿í¶È
 for($i=0;$i {
  $bartopx=$gridlabelwidth+(($i+1)*20)+($i*$barwidth);#¿ØÖÆÖù¿¿×óµÄ¾àÀë
  $barbottomx=$bartopx+$barwidth;  $barbottomy=$graphheight-1;#¿ØÖÆÖùµÄϱ߽ç
  $bartopy=$barbottomy-($graphdata[$i]*$graphscale);
  imagefilledrectangle($ima