<?php
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;//字型顏色
//--------參數設定函數
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->ITEMARRAY=$ItemArray;
$this->REPORTTYPE=$ReportType;
$this->BORDER=$Border;
}
function setFont($FontSize){
$this->FONTSIZE=$FontSize;
}
//----------------主體
function PrintReport(){
Header( "Content-type: image/gif");
//建立畫布大小
$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->imageLine();
break;
}
$this->printXY();
$this->printAll();
}
//-----------列印XY座標軸
function printXY(){
//畫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軸
//Y軸上刻度
$rulerY=$this->Y-$this->BORDER;
while($rulerY>$this->BORDER*2){
$rulerY=$rulerY-$this->BORDER;
ImageLine($this->IMAGE,$this->BORDER,$rulerY,$this->BORDER-2,$rulerY,$color);
}
//X軸上刻度
$rulerX=$rulerX+$this->BORDER;
while($rulerX<($this->X-$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);
}
}