ホームページ  >  記事  >  バックエンド開発  >  円グラフまたは棒グラフの PHP 生成クラスまたはサンプルを探しています

円グラフまたは棒グラフの PHP 生成クラスまたはサンプルを探しています

高洛峰
高洛峰オリジナル
2016-12-01 15:06:26955ブラウズ

PHPコード:---------------------------------------------- -- ----------------------------------
/*----------- -------------------------------------------------- -- ----------*/
//
// モジュール名: 3D 円グラフ クラス
//
// 作成者:Avenger(avenger@php.net) 最終更新日: 2002-10 - 30 11:19
// Copyright (c) 2002 by Avenger
/*-------------------------------- - --------------------------------------*/

//パブリック関数部分

//角度をラジアンに変換します
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) ); $deg)) * $va;
$y= sin(deg2Arc($deg)) * $vb;
return (array($x, $y));
}


//3D 円グラフ クラス

class Pie3d{

var $a; //楕円の主半軸
var $DataArray //各セクターのデータ
var $ColorArray;各セクタの色 0xを付けずに16進数で記述する必要があります
var $Fize; //フォントサイズ
//エッジと影は黒です

function Pie3d($pa=60,$pb=30,$sData) ="100,200,300,400,500 ", $sColor="ee00ff,dd0000,cccccc,ccff00,00ccff",$fontsize=1) {
$this->a=$pa;
$this->b=$pb;
$ this->DataArray=split(",",$sData);
$this->ColorArray=split(",",$sColor);
$this->Fsize=$fontsize;
}

関数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(){
$fsize=$this->Fsize;
$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);
$DataNumber=count($this->DataArray);

//$DataTotal
for($i=0;$iDataArray[$i]; //データを計算して

//背景を塗りつぶす
imagefill($image, 0, 0, imagecolorallocate($image, 255, 255, 255));

/ *
** 各セクターを描画
*/

$Degrees = 0;
for ($i = 0; $i < $DataNumber; $i++) {
$StartDegrees =round($Degrees);
$Degrees + = (($ this->DataArray[$i]/$DataTotal)*360);
$EndDegrees =round($Degrees);
$percent =number_format($this->DataArray[$i]/$DataTotal) *100, 1 );
list($R,$G,$B)=getRGB(hexdec($this->ColorArray[$i]));
$CurrentColor=imagecolorallocate($image,$R,$G) ,$B) ;
if ($R>60 および $R<256) $R=$R-60;
if ($G>60 および $G<256) $G=$G-60;
if ( $B>60 and $B<256) $B=$B-60;
$CurrentDarkColor=imagecolorallocate($image,$R,$G,$B);

//扇形の弧を描く
imagearc( $image,$PieCenterX,$ PieCenterY,$DoubleA,$DoubleB,$StartDegrees,$EndDegrees,$CurrentColor);

//直線を描く
list($ArcX, $ArcY) = pie_point($StartDegrees, $this ->a, $this-> ;b);
imageline($image,$PieCenterX,$PieCenterY,floor($PieCenterX + $ArcX),floor($PieCenterY + $ArcY),$CurrentColor);

/ /直線を描く
list($ArcX, $ArcY) = pie_point($EndDegrees,$this->a , $this->b);
imageline($image,$PieCenterX,$PieCenterY,ceil($ PieCenterX + $ArcX),ceil($PieCenterY + $ArcY),$CurrentColor);

//セクターを塗りつぶします
$MidPoint =round((($EndDegrees - $StartDegrees)/2) + $StartDegrees);
list ($ArcX, $ArcY) = Pie_point($MidPoint , $this->a*3/4 , $this->b*3/4);

imagefilltoborder($image,floor($PieCenterX + $ArcX) ),floor($PieCenterY + $ArcY),$ CurrentColor,$CurrentColor);
imagestring($image,$fsize,floor($PieCenterX + $ArcX-5),floor($PieCenterY + $ArcY-5),$ percent."%",$colorBorder);

//影を描画します
if ($StartDegrees>=0 and $StartDegreesif($EndDegrees<=180){
for($k = 1; $k < 15; $k++)
imagearc( $image,$PieCenterX, $PieCenterY+$k,$DoubleA, $DoubleB, $StartDegrees, $EndDegrees, $CurrentDarkColor);
}else{
for($k = 1) ; $k <15; $k++)
imagearc ($image,$PieCenterX, $PieCenterY+$k,$DoubleA, $StartDegrees, 180, $CurrentDarkColor);
}
}
}

//生成された画像
imagepng($image,'consture.png');
imagedestroy($image);
}//描画Pie()を終了
}//クラスを終了
$pie = new Pie3d;
$pie->Pie3d($pa =300,$pb=150,$sData="100,200,300,400,500", $sColor="ee00ff,dd0000,cccccc,ccff00,ddddaa",$fontsize=5);
$pie->DrawPie();
echo '< ;img src="consture.png" border=0 alt="交易分析图">';

?>

声明:
この記事の内容はネチズンが自主的に寄稿したものであり、著作権は原著者に帰属します。このサイトは、それに相当する法的責任を負いません。盗作または侵害の疑いのあるコンテンツを見つけた場合は、admin@php.cn までご連絡ください。