访问的网站显示建设中,石家庄网站快速排名,顺德网站优化公司,html5写的网站有什么好处本节内容#xff1a;PHP GD库生成扇形比例图。实现功能#xff1a;一些图形的百分比显示图#xff0c;像三个地区所占地多少或成绩等。这里分享一段php生成的扇形比例百分比显示程序代码#xff0c;需要phpGD库支持。代码#xff1a;复制代码 代码示例:/*** 生成扇形比例图…本节内容PHP GD库生成扇形比例图。实现功能一些图形的百分比显示图像三个地区所占地多少或成绩等。这里分享一段php生成的扇形比例百分比显示程序代码需要phpGD库支持。代码复制代码 代码示例:/*** 生成扇形比例图* 编辑www.jbxue.com*///填充图表的参数$ChartDiameter 60; //图表直径$ChartData array(30,70);//用于生成图表的数据可通过数据库来取得来确定也可以多个不过和颜色数组对应//把角度转换为弧度function radians($degrees){return($degrees*(pi()/180.0));}//取得在圆心为(00)圆上 x,y点的值function circle_point($degrees,$diameter){$xcos(radians($degrees))*($diameter/2);$ysin(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))];//画图Fimagearc($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 – $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);?