Home >Backend Development >PHP Tutorial >Class for generating horizontal and vertical column charts and line charts using GD library_PHP tutorial

Class for generating horizontal and vertical column charts and line charts using GD library_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:32:27912browse

I recently wrote a GD library to generate horizontal and vertical bar charts and line charts. It can be regarded as a teaching routine.
Class ImageReport{
var $X; //Image size X axis
var $Y;//Picture size Y axis
var $R;//Back color R value
var $G;//...G.
var $B;//...B .
var $TRANSPARENT;//Whether it is transparent 1 or 0
var $IMAGE;//Image object
//------------------ -
var $ARRAYSPLIT;//Specify the symbol used to separate values ​​
var $ITEMARRAY;//Value
var $REPORTTYPE;//Chart type, 1 is vertical column 2 is horizontal column 3 It is polyline shape
var $BORDER;//distance
//------------------
var $FONTSIZE;//font size
var $FONTCOLOR;//Font color
//--------Parameter setting function
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;
}
//---------- -----Body
function PrintReport(){
Header( "Content-type: image/gif");
//Create canvas size
$this->IMAGE=ImageCreate( $this-> > background);
}else{
//If you don’t want transparency, you can fill the background color
ImageFilledRectangle($this->IMAGE,0,0,$this->X,$this-> Y,$background);
}
//Parameter font size and color
$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();
}
//----------Print the XY coordinate axis
function printXY(){
//Draw the XY coordinate axis*/
$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-axis
ImageLine($this->IMAGE,$this->BORDER,$this->Y -$this->BORDER,$this->X-$this->BORDER,$this->Y-$this->BORDER,$color);//y-axis
//Y On-axis scale
$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);
}
//Scale on the X axis
$rulerX=$rulerX+$this->BORDER;
while($rulerX<($this->
$rulerX=$rulerX+$this->BORDER;
//ImageLine($this->IMAGE,$this->BORDER,10,$this->BORDER+10,10,$ color);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/508716.htmlTechArticleI recently wrote a GD library to generate horizontal and vertical column charts and line charts, which is considered a teaching routine. Class ImageReport var
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn