PHP drawing to generate pie chart method, PHP drawing generated pie
In this paper, we describe the method of generating pie chart of PHP drawing. Share to everyone for your reference. Specific as follows:
The function to be implemented here is the population distribution ratio chart, which consists of a circle of sectors, each of which is not the same color.
Copy the Code code as follows: <?php
$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 consisting of multiple fan segments
$a 1=rand (0,360);
$sum = Array_sum ($array);
for ($j =0; $j<>
$a 2 = $a 1 + $arr _key[$j]/$sum *360;
Imagefilledarc ($im, 150,150,180,80, $a 1, $a 2, $color [$j],img_arc_pie);
$a 1 = $a 2;
}
Output image
Header ("Content-type:image/png");
Imagepng ($im);
Shut down
Imagedestroy ($im);
?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/947207.html www.bkjia.com true http://www.bkjia.com/PHPjc/947207.html techarticle PHP drawing To generate pie chart method, PHP drawing Generation Pie This article describes the PHP drawing of the method of generating pie chart. Share to everyone for your reference. As follows: here to achieve ...