php扇形スケールマップの生成例

2772 ワード

多くのサイトでは、3つの地域の敷地数や成績など、phpで生成された扇形の割合の割合表示プログラムコードを紹介していますが、phpGDライブラリのサポートが必要です.
 
  
//
$ChartDiameter = 60; //
$ChartData = array(30,70);// ,
//
function radians($degrees){return($degrees*(pi()/180.0));}
// (0,0) x,y
function circle_point($degrees,$diameter){$x=cos(radians($degrees))*($diameter/2);$y=sin(radians($degrees))*($diameter/2);return (array($x,$y));}
//
$ChartWidth = $ChartDiameter + 20;
$ChartHeight = $ChartDiameter + 20;
//
$ChartTotal = “”;
for($index = 0;$index < count($ChartData);$index++){
$ChartTotal += $ChartData[$index];
}
$ChartCenterX = $ChartDiameter/2 + 10;
$ChartCenterY = $ChartDiameter/2 + 10;
//
$image = imagecreate($ChartWidth, $ChartHeight);
//
$colorBody = imagecolorallocate($image, 0xFF, 0xFF, 0xFF);
$colorBorder = imagecolorallocate($image, 0×00, 0×00, 0×00);
$colorText = imagecolorallocate($image, 0×00, 0×00, 0×00);
$colorSlice[] = imagecolorallocate($image, 0xFF, 0×00, 0×00);//
$colorSlice[] = imagecolorallocate($image, 0×00, 0xFF, 0×00);
//
imagefill($image, 0, 0, $colorBody);
//
$Degrees = 0;
for($index = 0; $index < count($ChartData); $index++){
$StartDegrees = round($Degrees);
$Degrees += (($ChartData[$index]/$ChartTotal)*360);
$EndDegrees = round($Degrees);
$CurrentColor = $colorSlice[$index%(count($colorSlice))];
// F
imagearc($image,$ChartCenterX,$ChartCenterY,$ChartDiameter,$ChartDiameter,$StartDegrees,$EndDegrees, $CurrentColor);
//
list($ArcX, $ArcY) = circle_point($StartDegrees, $ChartDiameter);
imageline($image,$ChartCenterX,$ChartCenterY,floor($ChartCenterX + $ArcX),
floor($ChartCenterY + $ArcY),$CurrentColor);
//
list($ArcX, $ArcY) = circle_point($EndDegrees, $ChartDiameter);
imageline($image,$ChartCenterX,$ChartCenterY,ceil($ChartCenterX + $ArcX),
ceil($ChartCenterY + $ArcY),$CurrentColor);
//
$MidPoint = round((($EndDegrees �C $StartDegrees)/2) + $StartDegrees);
list($ArcX, $ArcY) = circle_point($MidPoint, $ChartDiameter/2);
imagefilltoborder($image,floor($ChartCenterX + $ArcX),floor($ChartCenterY + $ArcY),
$CurrentColor,$CurrentColor);
}
// , , , GIF 。
header(“Content-type: image/png”);
imagegif($image);
?>