Heim  >  Artikel  >  Backend-Entwicklung  >  php绘图之生成饼状图的方法_php技巧

php绘图之生成饼状图的方法_php技巧

WBOY
WBOYOriginal
2016-05-16 20:24:57982Durchsuche

本文实例讲述了php绘图之生成饼状图的方法。分享给大家供大家参考。具体如下:

这里要实现的功能是人口分布比例图,由扇形组成一个圆,每个扇形颜色不一样。

复制代码 代码如下:
$array = array("北京"=>1925,"上海"=>2016,"广州"=>1256,"深圳"=>980);
$arr_key = array_keys($array);
$color = array();
$im = imagecreatetruecolor(300,300);
for($i=1;$i  $color[] = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
}

//创建饼状图,由多个扇形组成
$a1=rand(0,360);
$sum = array_sum($array);
for($j=0;$j  $a2 = $a1 + $arr_key[$j]/$sum*360;
 imagefilledarc($im,150,150,180,80,$a1,$a2,$color[$j],IMG_ARC_PIE);
 $a1 = $a2;
}

//输出图像
header("content-type: image/png");
imagepng($im);
//关闭
imagedestroy($im);
?>

希望本文所述对大家的php程序设计有所帮助。

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn