如果是一组数据,用数组就可以,如
$values = array(23,32,35,57,12,3,36,54,32,15,43); 
$columns  = count($values);
 $width = 300; 
   $height = 200;
 $padding = 5; 
$im        = imagecreate($width,$height); 
  $white     = imagecolorallocate ($im,0xff,0xff,0xff); 
imagefilledrectangle($im,0,0,$width,$height,$white); 
$max_value = max($values);
    for($i=0;$i<$columns;$i++) 
        {
    
        $column_height = ($height / 100) * (( $values[$i] / $max_value)
 
*100); 
 
        $x1 = $i*$column_width; 
        $y1 = $height-$column_height; 
        $x2 = (($i+1)*$column_width)-$padding; 
        $y2 = $height;
 
        imagefilledrectangle($im,$x1,$y1,$x2,$y2,$gray);
 
  
        imageline($im,$x1,$y1,$x1,$y2,$gray_lite); 
        imageline($im,$x1,$y2,$x2,$y2,$gray_lite); 
        imageline($im,$x2,$y1,$x2,$y2,$gray_dark); 
        }
 
 
   header ("Content-type: image/png");   imagepng($im); 
?>
可是如是2组相比较的数据呢?如
日期      地区一    地区二
一月      300           600
二月      600           700
三月      450          900
四月       790        600
五月      600        300日期为横轴,做条形图,该如何呢?多谢 

解决方案 »

  1.   

    这是 JpGraph 吗?
      

  2.   

    require 'jpgraph/jpgraph.php';
    require 'jpgraph/jpgraph_bar.php';
    $graph = new Graph(800,600);
    $graph->SetScale('textlin');
    $graph->SetMargin(50,30,30,60);
    $graph->title->Set('2012年前9个月PHP使用率统计图');
    $graph->title->SetFont(FF_SIMSUN,FS_BOLD);
    $graph->xaxis->title->Set('月份');
    $graph->xaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
    $graph->yaxis->title->Set('使用率');
    $graph->yaxis->title->SetFont(FF_SIMSUN,FS_BOLD);
    $graph->yaxis->SetTitleMargin(30);
    $datay = array(5.7,5.6,5.5,5.3,5.7,5.3,5,5.5,5.6);
    $bar = new BarPlot($datay);
    $graph->Add($bar);
    $graph->stroke();
    上面这个是的,但是只能实现一组数,我有两组数地区一和地区二相比较(要求每两个条形图并排列)按1月2月3月在横轴上展开,如何实现?多谢