PHP Drawing Generation Pie chart method, PHP drawing generation pie _php Tutorial

Source: Internet
Author: User

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 ...

  • Related Article

    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.