(原创)php实现报表类

本文分享了如何使用PHP原创实现报表类,包括曲线图、饼图和柱形图的绘制,提供了相关代码调用方法。
摘要由CSDN通过智能技术生成

原创内容....实现曲线图,饼图,柱形图.

转贴请注明出处,

http://blog.csdn.net/liq330

效果图:

原代码如下:

<? php

class  ImageReport
{
   
var   $Image ; // 图片对像

   
var   $ImageName ; // 报表名称
    var   $ImageType ; // 报表类型
   
   
var   $ImageWidth ; // 图片宽
    var   $ImageHeight ; // 图片高
   

   
var   $BgImage ; // 背景图片
    var   $BgR ; // 背景颜色R值
    var   $BgG ; // 背景颜色G值
    var   $BgB ; // 背景颜色B值

   
var   $FontSize ; // 字体大小
    var   $FontColor ; // 字体颜色

   
var   $ItemArray ; // 数据数组
    var   $ItemInterval ; // 两项间的间隔
    var   $XName ; // x轴的名称
    var   $YName ; // y轴的名称
    var   $isScale ; // 是否显示刻度值
    var   $margin ; // 边距

   //字体

    var   $font   =   ' arial.ttf ' ;    
   
    
function  ImageReport()
    {
        
return  ;
    }

   
// 设置图片基本信息
    function  setImage( $ImageName , $ImageType , $ImageWidth = 500 , $ImageHeight = 400 )
   {
        
$this -> ImageName   = $ImageName ;
     
$this -> ImageType   = $ImageType ;
     
$this -> ImageWidth  = $ImageWidth ;
     
$this -> ImageHeight = $ImageHeight ;
   }
   
   
// 设置坐标
    function  setItem( $ItemArray , $ItemInterval = " 20 " , $XName = "" , $YName = "" , $isScale = true )
   {
        
$this -> ItemArray     = $ItemArray ;
     
$this -> ItemInterval  = $ItemInterval ;
     
$this -> XName         = $XName ;
     
$this -> YName         = $YName ;
     
$this -> isScale       = $isScale ;
   }
   
   
// 设置图片背景
    function  setBg( $BgR = " 235 " , $BgG = " 255 " , $BgB = " 255 " , $BgImage = "" )
   {
        
$this -> BgR      = $BgR ;
     
$this -> BgG      = $BgG ;
     
$this -> BgB      = $BgG ;
     
$this -> BgImage  = $BgImage ;
   }
   
   
// 设置字体
    function  setFont( $FontSize )
   {
     
$this -> FontSize   = $FontSize ;
     
$this -> margin     = $FontSize * 2 + 5 ;
     
// $this->FontColor =$FontColor;
   }

   
// 画主体
    function  drawReport()
   {
     
// 建立画布
      $this -> Image = imagecreatetruecolor( $this -> ImageWidth , $this -> ImageHeight);
     
// 填充背景色
      $background = ImageColorAllocate( $this -> Image , $this -> BgR , $this -> BgG , $this -> BgB);
          
     
// 画背景颜色
     ImageFilledRectangle( $this -> Image , 0 , 0 , $this -> ImageWidth , $this -> ImageHeight , $background );

     
// 画背景图片
      if ( ! empty ( $this -> BgImage))
     {
        
$this -> drawLogo();
     }
      
// 跟距参数,画不同的图片
      switch ( $this -> ImageType)
     {
         
case   " 1 " :
           
$this -> drawColumn();
           
break ;
         
case   " 2 " :
           
$this -> drawCurve();
           
break ;
         
case   " 3 " :
           
$this -> drawCircle();
           
break ;
         
default :
             
break ;
     }

   }
   
   
// 画柱状图
    function  drawColumn()
   {
     
// 调用画标题
      $this -> drawTitle();
     
// 调用画坐标
      $this -> drawXY();

     
// 获取数组的量
      $num = count ( $this -> ItemArray);
     
// 获取数组中的最大值
     //最大值

      $max = $this -> getArrayMax( $this -> ItemArray);
    

     
for ( $i = 0 ; $i < count ( $this -> ItemArray); $i ++ )
     {
        
// 随机颜色
         srand (( double ) microtime () * 1000000 );  
        
$R = Rand ( 50 , 200 );   
        
$G
  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 10
    评论
评论 10
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值