作参考吧
<html> 
<head> 
<title>柱状图</title> 
<meta http-equiv="Content-Type" content="text/html; charset=gb2312"> 
</head> 
<body bgcolor="#FFFFFF"> 
<? 
/* 
  Written by Caocao. 
  http://caocao.oso.com.cn 
  [email protected] 
*/ 
  class bar 
  { 
    var $bar_width=15;//柱宽 
    var $bar_height=400;//最大柱高 
    var $bar_color_light="CCCCCC";//柱色 
    var $bar_color_dark="000000";//阴影色 
    var $shadow=3;//阴影深度 
    var $space=5;//柱间距 
    var $data;//数据 
    var $result;//结果 
    var $style=1;//柱图样式 
    var $ispercent=1;//是否用百分比 
     
    function set_width_height($bar_width_input,$bar_height_input)//设置柱宽柱高 
    { 
      $this->bar_width=$bar_width_input; 
      $this->bar_height=$bar_height_input; 
    } 
     
    function set_bar_color($bar_color_light_input,$bar_color_dark_input)//设置柱色阴影色 
    { 
      $this->bar_color_light=$bar_color_light_input; 
      $this->bar_color_dark=$bar_color_dark_input; 
    } 
     
    function set_style($style_input)//设置柱图样式 
    { 
      $this->style=$style_input; 
    } 
     
    function set_shadow($shadow_input)//设置阴影深度 
    { 
      $this->shadow=$shadow_input; 
    } 
     
    function set_space($space_input)//设置柱间距 
    { 
      $this->space=$space_input; 
    } 
     
    function set_ispercent($ispercent_input)//设置是否用百分比 
    { 
      $this->ispercent=$ispercent_input; 
    } 
     
    function set_data($data_input)//设置数据 
    { 
      for ($i=0;$i<count($data_input);$i++) 
        $this->data[$i]=$data_input[$i]; 
    } 
     
    function preset_data()//数据处理 
    { 
      if ($this->ispercent) 
      { 
        $total_tmp=0; 
        for ($i=0;$i<count($this->data);$i++) 
          $total_tmp+=$this->data[$i]; 
        for ($i=0;$i<count($this->data);$i++) 
          $this->result[$i]=number_format(100*$this->data[$i]/$total_tmp,1); 
        return (0); 
      } 
      else 
      { 
        $tmp[0]=$this->data[0]; 
        $tmp[1]=$this->data[0]; 
        for ($i=0;$i<count($this->data);$i++) 
        { 
          if ($tmp[0]>$this->data[$i]) 
            $tmp[0]=$this->data[$i]; 
          if ($tmp[1]<$this->data[$i]) 
            $tmp[1]=$this->data[$i]; 
        } 
        return ($tmp); 
      } 
    } 
     
    function style_1() 
    { 
      $tmp=$this->preset_data(); 
      echo "<table border=0 cellspacing=0 cellpadding=".$this->space.">n"; 
      if (count($tmp)==1) 
      { 
        for ($i=0;$i<count($this->result);$i++) 
        { 
          echo "<tr><td>".$this->result[$i]."%</td><td><table height=".$this->bar_width." width=".ceil($this->result[$i]*$this->bar_height/100)." border=0 cellspacing=0 cellpadding=0 bgcolor=".$this->bar_color_light."><tr><td></td></tr></table></td></tr>n"; 
        } 
      } 
      else 
      { 
        for ($i=0;$i<count($this->data);$i++) 
        { 
          echo "<tr><td>".$this->data[$i]."</td><td><table height=".$this->bar_width." width=".ceil(100*($this->data[$i]-$tmp[0])/($tmp[1]-$tmp[0])+1)." border=0 cellspacing=0 cellpadding=0 bgcolor=".$this->bar_color_light."><tr><td></td></tr></table></td></tr>n"; 
        } 
      } 
      echo "</table>n"; 
    } 
     
    function display()//显示柱图 
    { 
      switch ($this->style) 
      { 
        case 1:$this->style_1();break; 
        
      } 
    } 
  } 
   
  $newdata=array(30,60,55,48,30,70,28,0); 
   
  $result=new bar; 
  $result->set_data($newdata); 
  $result->set_width_height(20,800); 
  $result->set_space(3); 
  $result->set_shadow(3); 
   
  $result->set_ispercent(0); 
  for ($i=1;$i<5;$i++) 
  { 
    $result->set_style($i); 
    $result->display(); 
  } 
  $result->set_ispercent(1); 
  for ($i=1;$i<5;$i++) 
  { 
    $result->set_style($i); 
    $result->display(); 
  } 
?> 
</body> 
</html>