How to generate a pie chart in php drawing, generate a pie in php drawing_PHP tutorial

WBOY
Release: 2016-07-13 10:09:08
Original
813 people have browsed it

How to generate pie chart by php drawing, generate pie by php drawing

The example in this article describes how to generate a pie chart using PHP drawing. Share it with everyone for your reference. The details are as follows:

The function to be implemented here is a population distribution proportion map, which consists of sectors forming a circle, and each sector has a different color.

Copy code The code is as follows:
$array = array("Beijing"=>1925,"Shanghai"=>2016,"Guangzhou"=>1256,"Shenzhen"=>980);
$arr_key = array_keys($array);
$color = array();
$im = imagecreatetruecolor(300,300);
for($i=1;$i<=count($array);$i++){
$color[] = imagecolorallocate($im,rand(0,255),rand(0,255),rand(0,255));
}

//Create a pie chart, composed of multiple sectors
$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;
}

//Output image
header("content-type: image/png");
imagepng($im);
//Close
imagedestroy($im);
?>

I hope this article will be helpful to everyone’s PHP programming design.

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/947207.htmlTechArticleHow to generate pie chart in php drawing, generate pie in php drawing. This article describes how to generate pie chart in php drawing. diagram method. Share it with everyone for your reference. The details are as follows: What needs to be achieved here...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!