-
-
class ImageReport{
- var $X;//圖片大小X軸
- var $Y;//圖片大小Y軸
- var $R;//背影色R值
- var $G;//...G.
- var $B;//...B.
- var $ TRANSPARENT;//是否透明1或0
- var $IMAGE;//圖片物件
- //-------------------
- var $ ARRAYSPLIT;//指定用於分隔數值的符號
- var $ITEMARRAY;//數值
- var $REPORTTYPE;//圖表類型,1為豎柱形2為橫柱形3為折線形
- var $BORDER;//距離
- //-------------------
- var $FONTSIZE;//字體大小
- var $FONTCOLOR;/ /字體顏色
-
- var $numX = 1;//X軸起始刻度值
- var $stepX = 1;//X軸每一個刻度間隔值
-
- //- -------參數設定函數
- function setImage($SizeX,$SizeY,$R,$G,$B,$Transparent){
- $this->X=$SizeX;
- $this->Y=$SizeY;
- $this->R=$R;
- $this->G=$G;
- $this->B=$B;
- $this ->TRANSPARENT=$Transparent;
- }
- function setItem($ArraySplit,$ItemArray,$ReportType,$Border){
- $this->ARRAYSPLIT=$ArraySplit;
- $this-this>ITEMARRAY =$ItemArray;
- $this->REPORTTYPE=$ReportType;
- $this->BORDER=$Border;
- }
- function setFont($FontSize){
- $this->FONTSI =$FontSize;
- }
- //X軸刻度值設定
- function setX($numX = 1, $stepX = 1){
- $this->numX = $numX;
- $this->stepX = $stepX;
- }
- //----------------主體
- function PrintReport(){
- //建立畫布大小
- $this->IMAGE=ImageCreate($this->X,$this->Y);
- //設定畫布背景色
- $background=ImageColorAllocate($this->IMAGE,$ this->R,$this->G,$this->B);
- if($this->TRANSPARENT=="1"){
- //背影透明
- Imagecolortransparent($this- >IMAGE,$background);
- }else{
- //如不要透明時可填充背景色
- ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this- >Y,$background);
- }
- //參數字體文字小及顏色
- $this->FONTCOLOR=ImageColorAllocate($this->IMAGE,255-$this->R,255-$ this->G,255-$this->B);
- Switch ($this->REPORTTYPE){
- case "0":
- break;
- case "1":
- $this->imageColumnS();
- break;
- case "2":
- $this->imageColumnH();
- break;
- case "3":
- $this $this ->imageLine();
- break;
- case "4":
- $this->imageCircle();
- break;
- }
- $this->printXY();
- $this->printAll();
- }
- //-----------印出XY座標軸
- function printXY(){
- $rulerY = $ rulerX = "";
- //畫XY座標軸*/
- $color=ImageColorAllocate($this->IMAGE,255-$this->R,255-$this->G,255-$this ->B);
- $xx=$this->X/10;
- $yy=$this->Y-$this->Y/10;
- ImageLine($this->IMAGE, $this->BORDER,$this->BORDER,$this->BORDER,$this->Y-$this->BORDER,$color);//X軸
- ImageLine($this->IMAGE,$ this->BORDER,$this->Y-$this->BORDER,$this->X-$this->BORDER,$this->Y-$this->BORDER,$color);//y軸
- imagestring($this->IMAGE, $this->FONTSIZE, $this->BORDER-2, $this->Y-$this->BORDER+5, "0", $color);
- / /Y軸上刻度
- $rulerY=$this->Y-$this->BORDER;
- $i = 0;
- while($rulerY>$this->BORDER*2){
- $rulerY=$rulerY-$this->BORDER;
- ImageLine($this->IMAGE,$this->BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);
-
- if($this->REPORTTYPE == 2){//橫柱圖
- imagestring($this->IMAGE, $this->FONTSIZE, $this->BORDER-10, $rulerY-2 -$this->BORDER*($i+.5), $this->numX, $color);
- $this->numX += $this->stepX;
- }
- $i++;
- }
- //X軸上刻度
- $rulerX=$rulerX+$this->BORDER;
- $i = 0;
- while($rulerXX- $this->BORDER*2)){
- $rulerX=$rulerX+$this->BORDER;
- //ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER +10,10,$color);
- ImageLine($this->IMAGE,$rulerX,$this->Y-$this->BORDER,$rulerX,$this->Y-$this->BORDER+ 2,$color);
-
- //刻度值
- if($this->REPORTTYPE == 1){//豎柱圖
- imagestring($this->IMAGE, $this- >FONTSIZE, $rulerX-2+$this->BORDER*($i+.5), $this->Y-$this->BORDER+5, $this->numX, $color);
- $this ->numX += $this->stepX;
- }else if($this->REPORTTYPE == 3){//折線圖
- imagestring($this->IMAGE, $this->FONTSIZE, $rulerX-2, $this->Y-$ this->BORDER +5, $this->numX, $color);
- $this->numX += $this->stepX;
- }
- $i++;
- }
- }
-
- //---------------- 垂直圖
- function imageColumnS(){
- $item_array=Split($this- >ARRAYSPLIT,$this- >ITEMARRAY);
- $num=Count($item_array);
- $item_max=0;
- for ($i=0;$i $item_max= Max($item_max,$item_array[$i]);
- }
- $xx=$這->邊框*2;
- //畫長條圖
- for ($i=0; $i srand((double)microtime()*1000000);
- if($這個->R!=255 && $這個->G!=255 && $這個->B! $this->B,200);
- }其他{
- $R=蘭特(50,200);
- $G=蘭特(50,200);
- $B=蘭特(50,200) ;
- }
- $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
- // 柱形高度
- $height=($this->Y- $this->BORDER)-($this->Y-$this->BORDER*2)*($ item_array[$i]/$item_max);
- ImageFilledRectangle($this->IMAGE,$xx,$ height,$xx+$this->BORDER,$this->Y-$this->BORDER,$color);
- ImageString($this->IMAGE,$this->FONTSIZE,$xx,$height-$ this->BORDER,$item_array[$i],$this->FONTCOLOR);
- //用於間隔
- $xx=$xx+$this->BORDER*2;
- }
- }
- //------------橫柱形圖
- function imageColumnH(){
- $item_array=Split($this->ARRAYSPLIT ,$this->ITEMARRAY) ;
- $num=Count($item_array);
- $item_max=0;
- for ($i=0;$i $item_max=Max($ item_max,$item_array[$i]);
- }
- $yy=$這個->Y-$這個->BORDER*2;
- //畫長條圖
- for ($i =0;$i srand((double)microtime()*1000000);
- if($這個->R! =255 && $這個->G! =255 && $這個->B! =255){
- $R=Rand($this->R,200);
- $G=Rand($this->G,200);
- $B=Rand($this-> B,200);
- }其他{
- $R=蘭特(50,200);
- $G=蘭特(50,200);
- $B=蘭特(50,200);
- }
- $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
- // 柱形長度
- $leight=($this->X-$this-> BORDER*2)*($item_array[$i]/$item_max);
- $leight = $leight 邊框? $this->BORDER : $leight;
- ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
- ImageString( $this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR);
- //用於間隔
- $yy=$yy-$this->BORDER*2;
- }
- }
- //----------------折線圖
- function imageLine(){
- $item_array=Split($this->; ARRAYSPLIT,$this->ITEMARRAY);
- $num=Count($item_array);
- $item_max=0;
- for ($i=0;$i $item_max=Max($item_max,$item_array[$i]);
- }
- $xx=$這->邊框;
- //畫長條圖
- for ($i=0;$i srand((double)microtime()*1000000);
- if( $這個->R! =Rand($this->G,200);
- $B=Rand($this->B,200);
- }其他{
- $R=蘭特(50,200);
- $G=蘭特(50,200);
- $B=蘭特(50,200);
- }
- $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
- // 柱形高度
- $height_now=($this->Y-$this->BORDER)-($this->Y-$this->BORDER*2)*($ item_array[$i] /$item_max);
- if($i!="0")
- ImageLine($this->IMAGE,$xx-$this->BORDER,$height_next,$xx,$height_now,$color) ;
-
- ImageString($this->IMAGE,$this->FONTSIZE,$xx+2,$height_now-$this->BORDER/2,$item_array[$i],$this-> ;字體顏色);
- $height_next=$height_now;
- //用於間隔
- $xx=$xx+$this->BORDER;
- }
- }
- //--- -------------餅狀圖
- function imageCircle(){
- $total = 0;
- $ item_array=Split($this->ARRAYSPLIT,$this-> ITEMARRAY);
- $num=Count($item_array);
- $item_max=0;
- for ($i=0;$i $item_max=Max ($item_max,$item_array[$i]);
- $total += $item_array[$我];
- }
- $yy=$this->Y-$this->BORDER*2;
-
- //畫餅狀圖的陰影部分
- $e=0;
- for ($i=0;$i srand((double )microtime()*1000000);
- if($this->R!=255 && $this->G!=255 && $this->B!=255){
- $R=蘭德( $這個->R,200);
- $G=Rand($this->G,200);
- $B=Rand($this->B,200);
- }其他{
- $R=蘭特(50,200);
- $G=蘭特(50,200);
- $B=蘭特(50,200);
- }
- $s=$e;
- $leight=$item_array[$i]/$total*360;
- $e=$s+$leight;
- $color=ImageColorAllocate( $this->IMAGE,$R,$G,$B);
- $colorarray[$i]=$color;
- //畫圓
- for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s, $ e, $顏色,IMG_ARC_PIE);
- //imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
- //ImageFilledRectangle($this->IMAGE,$this->BORDER,$yy-$this->BORDER,$leight,$yy,$color);
- //ImageString($this->IMAGE,$this->FONTSIZE,$leight+2,$yy-$this->BORDER,$item_array[$i],$this->FONTCOLOR) ;
- //用於間隔
- $yy=$yy-$this->BORDER*2;
- }
-
- //畫餅狀圖的表面部分
- $e=0;
- for ($i=0;$i srand((double)microtime()*1000000);
- if($this->R!=255 && $this->G!=255 && $this->B!=255){
- $R =蘭特($這個->R,200);
- $G=Rand($this->G,200);
- $B=Rand($this->B,200);
- }其他{
- $R=蘭特(50,200);
- $G=蘭特(50,200);
- $B=蘭特(50,200);
- }
- $s=$e;
- $leight=$item_array[$i]/$total*360;
- $e=$s+$leight;
- //$color= $colorarray[$i];
- $color=ImageColorAllocate($this->IMAGE,$R,$G,$B);
- //畫圓
- //for ($j = 90; $j > 70; $j--) imagefilledarc($this->IMAGE, 110, $j, 200, 100, $s , $ e, $color, IMG_ARC_PIE);
- imagefilledarc($this->IMAGE, 110, 70, 200, 100, $s, $e, $color, IMG_ARC_PIE);
- }
- }
- //----------------列印完成圖形
- function printAll(){
- ImagePNG($this->IMAGE ) ;
- ImageDestroy($this->IMAGE);
- }
- //-------------- 除錯
- function debug(){
- echo "X:".$this->X."Y:".$this->Y;
- echo "
BORDER:".$this->BORDER;
- $item_array=split($this->ARRAYSPLIT,$this->ITEMARRAY);
- $num=Count($item_array);
- echo "
數值:".$num." 數值:";
- for ($i=0;$i echo "
".$item_array[$i];
- }
- }
- }
- //$report->debug();//調式之用
- /*
- Header( "Content-type:image/png" ) ;
- $report=new ImageReport;
- $report->setImage(600,500,255,255,255,1);//參數(長,高,背影顏色R,G,B,是否透明1或0)
- $ temparray="0,260,400,124,48,720,122,440,475";//數值,用指定符號隔開
- $report->setItem(',',$temparray,3,23);//參數(次數值的值指定數字,樣式1為垂直柱圖2為橫柱圖3為折線圖4為圓餅圖,距離)
- $report->setFont(1);//字體大小1-10
- / /$report - >setX(1,1);//設定X軸初始值(初始初始值=1,初始初始值=1)
- $report->PrintReport();
- * /
- ?>
複製程式碼
|