Php plot to generate a pie chart. php plot to generate a pie chart. Php plot: how to generate a pie chart. php plot to generate a pie chart. This document describes how to generate a pie chart by using php plot. Share it with you for your reference. The details are as follows: how to generate a pie chart by drawing php, and how to generate a pie chart by drawing php
This article describes how to generate a pie chart using php plot. Share it with you for your reference. The details are as follows:
The function to be implemented here is the population distribution ratio chart, which consists of a circle with different colors.
The code is 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 slices
$ A1 = revert (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 help you with php programming.
Examples in this article describes how to generate a pie chart using php plot. Share it with you for your reference. The details are as follows...