文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>php生成html统计图

php生成html统计图

时间:2006-11-29  来源:yueming


/****************************************************************************
|    @Author:    etng
|    @Email:        etng2004[at]gmail.com etng2004[at]hotmail.com
|    @QQ:        35605690
|    @WangWang:    etng
|    @Homepage:    http://www.etng.net/
@FileName        :    draw.bar.php
@Description    :    生成统计图
@CreateTime        :    2004-12-10
@LastModify        :    2004-12-10
@Version        :    1.0beta
@Copyright        :    etng.net
|
|            做一个快乐的CODER!    PHP = Programme Help Perfect!
|
****************************************************************************/
header("Content-Type:text/html; charset=utf-8");
header("Content-Language:utf-8");
?>
=    new bar(200,15,5);
$pair    =    $arr=array(
                        '1月'    =>    250,
                        '2月'    =>    370,
                        '3月'    =>    621,
                        '4月'    =>    720,
                        '5月'    =>    326,
                        '6月'    =>    455,
                        '7月'    =>    132,
                        '8月'    =>    345,
                        '9月'    =>    611,
                        '10月'    =>    126,
                        '11月'    =>    551,
                        '12月'    =>    266
                        );
$bar->setData($pair);
echo "月平均销售额,单位:(万元)";
$bar->draw();
echo "月平均销售额,单位:(万元)";
$bar->draw(false);
echo "调试数据如下:";
echo "";
var_dump($bar);
echo "";
?>
/*
@柱状统计图
*/
class bar
{
    //颜色, 默认为20种, 如果客户数据超过20种, 则回到第一种, 如此循环.
    var $color    =    array(
                        '#97bd00','#009900','#cc3300',
                        '#ffcc00','#3366cc','#33cc33',
                        '#ff9933','#cccc99','#99cc66',
                        '#66ff99','#4f6600','#003300',
                        '#481000','#7d6400','#173064',
                        '#1a6a1a','#974b00','#78793c',
                        '#557e27','#009337'
                        );
    var $total    =    399;
    var $per    =    25;
    //柱与柱之间的间隔
    var $space    =    5;
    var $max    =    0;
    /*
    构造函数
    */
    function bar($T=399 ,$P=25 ,$S=5)
    {
            $this->total        = $T;//总高度或者宽度
            $this->per            = $P;//单元高度或者宽度
            $this->space        = $S;//各柱间隔
    }
    /*
    给出具体数据
    */
    function setData($pair)
    {
        $this->DATA        =    $pair;
        $values            =    array_values($pair);
                            asort($values);
        $this->max        =    array_pop($values);
    }
    function draw($H=true)
    {
        $H?$this->drawH():$this->drawV();
    }
    function drawH(){
        $cntColor=count($this->color);
        $i=0;
?>
  echo $this->space; ?>">
    foreach($this->DATA as $k=>$v){
            $curColor = $this->color[($i++)%$cntColor];
    ?>
  
    echo  /*打印左边标签*/ $k; ?>
   
   echo $this->per; ?>">
     
       echo floor(($this->total/$this->max)*$v);?>" bgstyle="color: /*柱状颜色*/ echo $curColor; ?>">
        /*在柱状图的顶端输出数值*/ echo $v; ?>
     
   
   
  
}
?>
  }//end function
    function drawV(){
        $cntColor=count($this->color);
        $i=0;
?>
   
    /*一定要设置为低部对齐*/ ?>
foreach($this->DATA as $k=>$v){
            $curColor = $this->color[($i++)%$cntColor];
?>
   
/*在柱状图的顶端输出数值*/
            echo $v;
?>
        echo floor(($this->total/$this->max)*$v);?>" border=0>
        
        /*柱状颜色*/ echo $curColor; ?>" width="/*第条柱的宽度*/ echo $this->per; ?>">
         
      /*打印低部对应标签*/ echo $k;?>
      
}//end for
?>
   
  
  }//end function
}//end class
?>
;
               
               
               

相关阅读 更多 +
排行榜 更多 +
幸运硬币官方正版下载

幸运硬币官方正版下载

休闲益智 下载
宝宝来找茬手机版 v9.86.00.00 安卓版

宝宝来找茬手机版 v9.86.00.00 安卓版

休闲益智 下载
翻滚飞机大战最新版 v1.0.4 安卓版

翻滚飞机大战最新版 v1.0.4 安卓版

飞行射击 下载