用gd来做,给你一个gd类做参考:图类,可显示多种图形
<?//图类
Class ImageReport{ 
var $X;//图片大小X轴 
var $Y;//图片大小Y轴 
var $R;//背影色R值 
var $G;//...G. 
var $B;//...B. 
var $TRANSPARENT;//是否透明1或0 
var $IMAGE;//图片对像 
//------------------- 
var $ARRAYSPLIT;//指定用于分隔数值的符号 
var $ITEMARRAY;//数值 
var $REPORTTYPE;//图表类型,1为竖柱形2为横柱形3为折线形 
var $BORDER;//距离 
//------------------- 
var $FONTSIZE;//字体大小 
var $FONTCOLOR;//字体颜色 
//--------参数设置函数 
function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){ 
$this->X=$SizeX;  
$this->Y=$SizeY;  
$this->R=$R;  
$this->G=$G;  
$this->B=$B;  
$this->TRANSPARENT=$Transparent;  
}  
function setItem($ArraySplit,$ItemArray,$ReportType,$Border){  
$this->ARRAYSPLIT=$ArraySplit;  
$this->ITEMARRAY=$ItemArray;  
$this->REPORTTYPE=$ReportType;  
$this->BORDER=$Border;  
}  
function setFont($FontSize){  
$this->FONTSIZE=$FontSize;  
}  
//----------------主体  
function PrintReport(){ 
//建立画布大小  
$this->IMAGE=ImageCreate($this->X,$this->Y);  
//设定画布背景色  
$background=ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B);  
if($this->TRANSPARENT=="1"){  
//背影透明  
Imagecolortransparent($this->IMAGE,$background);  
}else{  
//如不要透明时可填充背景色  
ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this->Y,$background);  
}  
//参数字体文小及颜色  
$this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);  
Switch ($this->REPORTTYPE){  
case "0":  
break;  
case "1":  
$this->imageColumnS();  //竖矩状图
break;
case "2":
$this->imageColumnH();  //横矩状图
break;  
case "3":  
$this->imageLine();  //折线图
break;
case "4":  
$this->imageCircle();  //饼图
break;    
}  
$this->printXY();  
$this->printAll();  
}  
//-----------打印XY坐标轴  
function printXY(){  
//画XY坐标轴*/  
$color=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this->B);  
$xx=$this->X/10;  
$yy=$this->Y-$this->Y/10;
ImageLine($this->IMAGE,$this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER,$color);//X轴  
ImageLine($this->IMAGE,$this->BORDER,$this->Y-$this->BORDER,$this->X-$this->BORDER,$this->Y-$this->BORDER,$color);//y轴  
//Y轴上刻度  
$rulerY=$this->Y-$this->BORDER;  
while($rulerY>$this->BORDER*2){  
$rulerY=$rulerY-$this->BORDER;  
ImageLine($this->IMAGE,$this->BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);  
}  
//X轴上刻度  
$rulerX=$rulerX+$this->BORDER;  
while($rulerX<($this->X-$this->BORDER*2)){  
$rulerX=$rulerX+$this->BORDER;  
//ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER+10,10,$color);  
ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BORDER,$rulerX,$this->Y-$this->BORDER+2,$color);  
}  
}  //--------------竖柱形图  
function imageColumnS(){  
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
$item_max=0;  
for ($i=0;$i<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

$xx=$this->BORDER*2;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//柱形高度  
$height=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);  
ImageFilledRectangle($this->IMAGE,$xx,$height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color);  
ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$this->BORDER,$item_array[$i],$this->FONTCOLOR);  
//用于间隔  
$xx=$xx+$this->BORDER*2;  
}  
}  
//-----------横柱形图  
function imageColumnH(){  
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
$item_max=0;  
for ($i=0;$i<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

$yy=$this->Y-$this->BORDER*2;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}  
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//柱形长度  
$leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);  
ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);  
ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);  
//用于间隔  
$yy=$yy-$this->BORDER*2;  
}  
}
//--------------折线图  
function imageLine(){  
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
$item_max=0;  
for ($i=0;$i<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

//$xx=$this->BORDER;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}  
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//柱形高度  
$height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($item_array[$i]/$item_max);  
if($i!="0"){  
ImageLine($this->IMAGE,$xx,$height_next,$xx+$this->BORDER,$height_now,$color);  
}  
ImageString($this->IMAGE,$this->FONTSIZE,$xx+$this->BORDER,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR);  
$height_next=$height_now;  
//用于间隔  
$xx=$xx+$this->BORDER;  
}  
}  
//--------------饼状图
function imageCircle(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);  
$num=Count($item_array);  
$item_max=0;  
for ($i=0;$i<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]);
$total += $item_array[$i];

$yy=$this->Y-$this->BORDER*2;  

//画饼状图的阴影部分  
$e=0;
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}
$s=$e;
$leight=$item_array[$i]/$total*360;
$e=$s+$leight;
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
$colorarray[$i]=$color;  
//画圆  
for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $e, $color, IMG_ARC_PIE);  
//imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);  
//ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);  
//ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);  
//用于间隔  
$yy=$yy-$this->BORDER*2;  
}

//画饼状图的表面部分
$e=0;
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}
$s=$e;
$leight=$item_array[$i]/$total*360;
$e=$s+$leight;
//$color=$colorarray[$i];
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//画圆  
//for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $e, $color, IMG_ARC_PIE);  
imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);  
}  
}  
//--------------完成打印图形  
function printAll(){  
ImagePNG($this->IMAGE);
ImageDestroy($this->IMAGE);  
}

解决方案 »

  1.   

    上接上面:
    //--------------调试  
    function debug(){  
    echo "X:".$this->X."<br/>Y:".$this->Y;  
    echo "<br/>BORDER:".$this->BORDER;  
    $item_array=split($this->ARRAYSPLIT,$this->ITEMARRAY);  
    $num=Count($item_array);  
    echo "<br/>数值个数:".$num."<br/>数值:";  
    for ($i=0;$i<$num;$i++){ 
    echo "<br/>".$item_array[$i];  
    }  
    }  
    }  
    //$report->debug();//调式之用Header( "Content-type:image/png");
    $report=new ImageReport;
    $report->setImage(600,300,255,255,255,1);//参数(长,宽,背影色R,G,B,是否透明1或0)  
    $temparray="100,260,400,320,260,120";//数值,用指定符号隔开  
    $report->setItem(',',$temparray,4,20);//参数(分隔数值的指定符号,数值变量,样式1为竖柱图2为横柱图3为折线图4为饼图,距离)  
    $report->setFont(1);//字体大小1-10  
    $report->PrintReport();
    ?>
      

  2.   

    楼上的,真强啊,呵呵,我也来贴一个我自己做的,不过没有那么麻烦就是了
    index.php:
    <?
    include("config.inc.php");$sql = "select * from vote";
    $result = mysql_query($sql);
    $num = mysql_num_rows($result);
    $result_new = mysql_query("select * from vote where vote_id = $num");
    $vote = mysql_fetch_object($result_new);
    $votetext = explode("|||",$vote->vote_text);
    $votenum = sizeof($votetext);
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>投票统计</title>
    </head><body>
    <form name="form1" method="post" action="vote.php">
    <table width="400" border="0" align="center" cellpadding="0" cellspacing="0">
      <tr>
        <td height="25" align="center"><?=$vote->vote_title;?></td>
      </tr>
      <tr>
        <td><table align="center" cellpadding="0" cellspacing="0" border="0">
    <?
    for($i=0;$i<$votenum-1;$i++)
    {
    ?>
    <tr>
      <td width="10%"><input type="radio" name="vote" value="<?=$i;?>"></td>
      <td width="90%">&nbsp;<? echo "$votetext[$i]";?></td>
    </tr>
    <?
    }
    ?></table></td>
      </tr>
      <tr>
       <td align="right">
    <input type="hidden" name="voteid" value="<?=$vote->vote_id?>">
    <input type="submit" name="toupiao" value="投票"></td>
      </tr>
    </table>
    </form>
    </body>
    </html>
      

  3.   

    <?
    include("config.inc.php");
    require("fun.php");
    error_reporting(0);if($_POST['voteid'] == "")
    {
    $_POST['voteid'] = 1;
    }
    $votetime = time();
    $nowtime = date("Y年m月d日 H点i分s秒");
    $overtime=date("Y-m-d");
    $sql = "select * from vote where vote_id = ".$_POST['voteid']."";
    $result = mysql_query($sql);
    $vote = mysql_fetch_object($result);
    ?>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>投票结果</title>
    </head><body>
    <?
    if($overtime >$vote->enddate)
    {
    echo"<table width=300 height=30 align=center cellpadding=0 cellspacing=0 border=0>
    <tr>
                <td>本次调查已经结束,欢迎下次参与</td>
    </tr>
         </table>
         <meta http-equiv=refresh content='2;url=index.php'>";
    }
    else if(has_voted())
    {
     echo"<table width=300 height=30 align=center cellpadding=0 cellspacing=0 border=0>
    <tr>
        <td>您已经参加过投票了,欢迎下次参与</td>
    </tr>
          </table>
           <meta http-equiv=refresh content='2;url=index.php'>";
    }
    else
    {
    $vote_array = explode("|||",$vote->vote_count);
    $vote_array[$_POST['vote']]+=1;
    $vote_total = $vote->vote_total+=1;
    $votetext=explode("|||",$vote->vote_text);
    if(isset($_POST['vote']))
    {
                $vote_count=implode('|||',$vote_array);
                $upsql ="update vote set vote_count='".$vote_count."',vote_total=".$vote_total." where vote_id=".$_POST['voteid']."";
       $result = mysql_query($upsql);
    }
    echo"<table width=600 border=1 align=center cellpadding=0 cellspacing=0>
           <tr align=center> 
    <td height=25 colspan=3>本次调查话题:$vote->vote_title</td>
           </tr>
           <tr align=center> 
    <td width=250 height=25>调查内容</td>
    <td width=100>人数</td>
    <td width=250>比例</td>
            </tr>";
    for($j=0;$j<sizeof($votetext);$j++)
        $vote_nums+=$vote_array[$j];
    for($j=0;$j<sizeof($votetext);$j++)
    {   
        @$aaa[$j]=100*$vote_array[$j]/$vote_nums;
         $aaa[$j]=number_format($aaa[$j],1);
         echo "<tr>
      <td>$votetext[$j]</td>
      <td>$vote_array[$j]票</td>
      <td valign=middle><img src=vote.jpg width=$aaa[$j] height=15>$aaa[$j]%</td>
                                 </tr>";
    }
    echo"
    <tr align=center>
     <td colspan=3>截止".$nowtime."为止,共有".$vote_total."人参加投票!</td>
    </tr>
    </table>
    ";
    }
    ?>
    </body>
    </html>呵呵,这个是仿照人家的例子改了一下,不够成熟,希望高手来给点意见~