Your Ad Here
首页 | 编程语言 | 网站建设 | 游戏天堂 | 冲浪宝典 | 网络安全 | 操作系统 | 软件时空 | 硬件指南 | 病毒相关 | IT 认证
软讯网络 > 网站建设 > PHP > php生成html统计图
【标  题】:php生成html统计图
【关键字】:php,html
【来  源】:http://www.cublog.cn/u/16928/showart.php?id=207846

php生成html统计图

Your Ad Here <?php
/****************************************************************************
|    @Author:    etng
|    @Email:        etng2004[at]gmail.com etng2004[at]hotmail.com
|    @QQ:        35605690
|    @WangWang:    etng
|    @Homepage:    [url]http://www.etng.net/[/url]
@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");
?>
<script language="JavaScript">
<!--
function toggleNext(o){
        var obj=o.nextSibling;
        if(obj.style.display=="none"){
            obj.style.display="block";
        }else{
            obj.style.display="none";
        }
}
//-->
</script>
<?php
$bar    
=    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 
"<h3>月平均销售额,单位:(万元)</h3>";
$bar->draw();
echo 
"<h3>月平均销售额,单位:(万元)</h3>";
$bar->draw(false);
echo 
"<h3 onclick=\"toggleNext(this);\">调试数据如下:</h3>";
echo 
"<pre style='display:none;'>";
var_dump($bar);
echo 
"</pre>";
?>

<?php
/*
@柱状统计图
*/
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;
?>
  <table border="0" cellpadding="0" cellspacing="<?php echo $this->space?>">
    <?php
        
foreach($this->DATA as $k=>$v){
            
$curColor $this->color[($i++)%$cntColor];
    
?>

  <tr>
    <td><p align="right"><?php echo  /*打印左边标签*/ $k?></td>
    <td>
   <table border="0" cellpadding="0" cellspacing="0" height="<?php echo $this->per?>">
     <tr>
       <td width="<?echo floor(($this->total/$this->max)*$v);?>" bgstyle="color: <?php /*柱状颜色*/ echo $curColor?>"> </td>
       <td> <?php /*在柱状图的顶端输出数值*/ echo $v?></td>
     </tr>
   </table>
   </td>
  </tr>
<?php
      
}
?>
</table>
  <?php
    
}//end function 

    
function drawV(){
        
$cntColor=count($this->color);
        
$i=0;
?>
    <table border=0>
    <tr valign="bottom"><?php /*一定要设置为低部对齐*/ ?>
<?php
        
foreach($this->DATA as $k=>$v){
            
$curColor $this->color[($i++)%$cntColor];
?>
    <td align="center">
<?php
      
/*在柱状图的顶端输出数值*/
            
echo $v
?>
        <table height="<?echo floor(($this->total/$this->max)*$v);?>" border=0>
        <tr>
        <td bgstyle="color: <?php /*柱状颜色*/ echo $curColor?>" width="<?php /*第条柱的宽度*/ echo $this->per?>"></td>
          </tr>
      </table><font style="color: #3F7F9F"><?php /*打印低部对应标签*/ echo $k;?></font>
      </td>
<?php 
        
}//end for
?>
    </tr>
  </table>
  <?php
    
}//end function 
}//end class
?>
;
smarty 学习:【上一篇】
获得客户端ip的范例代码::【下一篇】
【相关文章】
  • Apache2.2.3+PHP5.2.0+MySQL5.0.27+openssl0.98d安装笔记
  • 黑客教程系列之微型PHP木马的探讨
  • Real-Time HTML editor
  • 一款很有趣的开源VS2005插件:CopySourceAsHtml
  • 关于三个PHP常用外部程序执行函数的比较分析
  • 常见的 PHP 设计模式分析
  • JSP Struts之HTML标签库详解
  • 使用freemarker给cms生成静态html
  • Python的difflib模块HtmlDiff
  • jsp与html的路径问题
  • 【随机文章】
  • Tomcat下JSP、Servlet和JavaBean配置
  • net命令详解续
  • Borland C++Builder 5.0教程(6)
  • AIX 5L 学习大纲/简易教程(2)(未经许可,请勿COPY)
  • 半透明显示图片
  • squid-2.5STABLE13的http代理+mysql认证(mysql_auth-0.8)
  • 快乐的钥匙——为什么要烦?
  • 专业专题点评:浅谈系统间数据传递与数据一致性的核心技术模式
  • 电脑维护心得 (新手必看)
  • 网络安全产品技术发展趋势(3)
  • 【相关评论】
    没有相关评论
    【发表评论】
    姓名:
    邮件:
    随机码*
    评论*
          
    |  首 页  |  版权声明  |  联系我们   |  网站地图  |
    CopyRight © 2004-2007 bbb软讯网络 All Rigths Reserved.