Php plot generation of pie chart

Source: Internet
Author: User
This article mainly introduces how to generate a pie chart by using php plot. It involves the use of the imagefilledarc method in the GD library. For more information, see

This article mainly introduces how to generate a pie chart by using php plot. It involves the use of the imagefilledarc method in the GD library. For more information, see

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.