Home Backend Development PHP Tutorial Code to achieve line chart effect under PHP_PHP tutorial

Code to achieve line chart effect under PHP_PHP tutorial

Jul 21, 2016 pm 03:55 PM
php var Down code picture size accomplish Effect of

Class ImageReport{
var $X;//Picture 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 is polyline
var $BORDER;//Distance
//------ -------------
var $FONTSIZE;//Font size
var $FONTCOLOR;//Font color
//--------Parameter settings 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; $ItemArray;
$this->REPORTTYPE=$ReportType;
$this->BORDER=$Border; ;FONTSIZE=$FontSize;
}
//----------------Body
function PrintReport(){
Header( "Content-type: image/gif");
//Create canvas size
$this->IMAGE=ImageCreate($this->X,$this->Y);
//Set canvas background Color
$background=ImageColorAllocate($this->IMAGE,$this->R,$this->G,$this->B);
if($this->TRANSPARENT= ="1"){
//Background transparent
Imagecolortransparent($this->IMAGE,$background);
}else{
//If you don’t want transparency, you can fill in 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(); function printXY(){
//Draw 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
//scale on Y-axis
$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->X-$this->BORDER*2)){
$rulerX=$rulerX+$this->BORDER; ->IMAGE,$this->BORDER,10,$this->BORDER+10,10,$color);
ImageLine($this->IMAGE,$rulerX,$this->Y -$this->BORDER,$rulerX,$this->Y-$this->BORDER+2,$color);
}
}

//--- -----------Vertical Column Chart
function imageColumnS(){
$item_array=Split($this->ARRAYSPLIT,$this->ITEMARRAY);
$ num=Count($item_array);
$item_max=0; $i]);

$xx=$this->BORDER*2;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(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<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

$yy=$this->Y-$this->BORDER*2;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(50,200);  
}  
$color=ImageColorAllocate($this->IMAGE,$R,$G,$B);  
//柱形长度  
$leight=($this->X-$this->BORDER*2)*($item_array[$i]/$item_max);  
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<$num;$i++){ 
$item_max=Max($item_max,$item_array[$i]); 

//$xx=$this->BORDER;  
//画柱形图  
for ($i=0;$i<$num;$i++){ 
srand((double)microtime()*1000000); 
if($this->R!=255 && $this->G!=255 && $this->B!=255){  
$R=Rand($this->R,200);  
$G=Rand($this->G,200);  
$B=Rand($this->B,200);  
}else{  
$R=Rand(50,200);  
$G=Rand(50,200);  
$B=Rand(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,$height_next,$xx+$this->BORDER,$height_now,$color);  
}  
ImageString($this->IMAGE,$this->FONTSIZE,$xx+$this->BORDER,$height_now-$this->BORDER/2,$item_array[$i],$this->FONTCOLOR);  
$height_next=$height_now;  
//用于间隔  
$xx=$xx+$this->BORDER;  
}  
}  

//--------------完成打印图形http://knowsky.com  
function printAll(){  
ImageGIF($this->IMAGE);  
ImageDestroy($this->IMAGE);  
}
//-------------Debugging
function debug(){
echo "X:".$this->X."
Y: ".$this->Y; ".$this->Y; "
echo "
BORDER:".$this->BORDER; ".$this->BORDER; ;
$num=Count($item_array);
echo "
Number of values: ".$num."
Number:";
for ($i=0;$i< ;$num;$i++){
echo "
".$item_array[$i];
}
}
}

$report=new ImageReport;
$report->setImage(600,300,255,255,255,1);//Parameters (length, width, background color R, G, B, whether it is transparent 1 or 0)
$temparray="50,25,100,250,180,200,150,220,200,150,50,25,10 0,250,180,200,150,220,200,150 ";//Values, separated by specified symbols
$report->setItem(',',$temparray,3,20);//Parameters (specified symbols that separate values, numerical variables, style 1 is vertical Column chart 2 is a horizontal bar chart and chart 3 is a line chart, distance)
$report->setFont(1);//Font size 1-10
$report->PrintReport();
/ /$report->debug();//For debugging purposes
?>

http://www.bkjia.com/PHPjc/318343.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/318343.htmlTechArticle?php ClassImageReport{ var$X;//Picture 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;//Picture Object...
Statement of this Website
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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

CakePHP Project Configuration CakePHP Project Configuration Sep 10, 2024 pm 05:25 PM

In this chapter, we will understand the Environment Variables, General Configuration, Database Configuration and Email Configuration in CakePHP.

PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian PHP 8.4 Installation and Upgrade guide for Ubuntu and Debian Dec 24, 2024 pm 04:42 PM

PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

CakePHP Date and Time CakePHP Date and Time Sep 10, 2024 pm 05:27 PM

To work with date and time in cakephp4, we are going to make use of the available FrozenTime class.

CakePHP Working with Database CakePHP Working with Database Sep 10, 2024 pm 05:25 PM

Working with database in CakePHP is very easy. We will understand the CRUD (Create, Read, Update, Delete) operations in this chapter.

CakePHP File upload CakePHP File upload Sep 10, 2024 pm 05:27 PM

To work on file upload we are going to use the form helper. Here, is an example for file upload.

CakePHP Routing CakePHP Routing Sep 10, 2024 pm 05:25 PM

In this chapter, we are going to learn the following topics related to routing ?

Discuss CakePHP Discuss CakePHP Sep 10, 2024 pm 05:28 PM

CakePHP is an open-source framework for PHP. It is intended to make developing, deploying and maintaining applications much easier. CakePHP is based on a MVC-like architecture that is both powerful and easy to grasp. Models, Views, and Controllers gu

CakePHP Creating Validators CakePHP Creating Validators Sep 10, 2024 pm 05:26 PM

Validator can be created by adding the following two lines in the controller.

See all articles