Home >Backend Development >PHP Tutorial >PHP object programming to implement 3D pie chart_PHP tutorial

PHP object programming to implement 3D pie chart_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 16:54:26861browse

//Public function
//Convert angles to radians
function deg2Arc($degrees) {
return($degrees * (pi()/180.0));
}
//RGB
function getRGB($color){
$R=($color>>16) & 0xff;
$G=($color>>8) & 0xff;
$B=($color) & 0xff;
return (array($R,$G,$B));
}
// Obtain the center of the ellipse (0, 0) The value of the x, y point on the ellipse
function pie_point($deg,$va,$vb){
$x= cos(deg2Arc($deg)) * $va;
$y = sin(deg2Arc($deg)) * $vb;
return (array($x, $y));
}
//3D pie chart class
class Pie3d{
var $a; //The major semi-axis of the ellipse
var $b; //The minor semi-axis of the ellipse
var $DataArray; //The data of each sector
var $ColorArray; //The data of each sector The color requirements are written in hexadecimal but do not add 0x in front
//The edge and shadow are black
function Pie3d($pa=100,$pb=60,$sData="100,200,300,400,500", $sColor= "ee00ff,dd0000,cccccc,ccff00,00ccff")
{
$this->a=$pa;
$this->b=$pb;
$this-> DataArray=split(",",$sData);
$this->ColorArray=split(",",$sColor);
}
function setA($v){
$ this->a=$v;
}
function getA(){
return $this->a;
}
function setB($v){
$ this->b=$v;
}
function getB(){
return $this->b;
}
function setDataArray($v){
$ this->DataArray=split(",",$v);
}
function getDataArray($v){
return $this->DataArray;
}
function setColorArray ($v){
$this->ColorArray=split(",",$v);
}
function getColorArray(){
return $this->ColorArray;
}

function DrawPie(){
$image=imagecreate($this->a*2+40,$this->b*2+40);
$PieCenterX= $this->a+10;
$PieCenterY=$this->b+10;
$DoubleA=$this->a*2;
$DoubleB=$this-> b*2;
list($R,$G,$B)=getRGB(0);
$colorBorder=imagecolorallocate($image,$R,$G,$B);

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/631788.htmlTechArticle?php //Public functions //Convert angles to radians function deg2Arc($degrees) { return($degrees * (pi()/180.0)); } //RGB function getRGB($color){ $R=($color16) 0xff; $G=($color8) 0xff;...
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