PHP generated fan scale diagram example _php tutorial

Source: Internet
Author: User
We will see a number of graphs on a number of sites showing graphs, such as the number of places in three regions or achievements, etc., to introduce a piece of PHP generated by the fan percentage display program code, but use it first need to have PHPGD library support.
Copy CodeThe code is as follows:
Fill the parameters of the chart
$ChartDiameter = 60; Chart diameter
$ChartData = Array (30,70);//The data used to generate the chart can be obtained from the database to be determined or multiple but corresponding to the color array
Convert the angle to radians
function radians ($degrees) {return ($degrees * (pi ()/180.0));}
Gets the value of the X, Y point on the Circle Circle (0,0)
function Circle_point ($degrees, $diameter) {$x =cos (radians ($degrees)) * ($diameter/2); $y =sin (radians ($degrees)) * ($ DIAMETER/2); return (Array ($x, $y));}
Determine the size of a graphic
$ChartWidth = $ChartDiameter + 20;
$ChartHeight = $ChartDiameter + 20;
Determine the total number of statistics
$ChartTotal = "";
for ($index = 0; $index < count ($ChartData); $index + +) {
$ChartTotal + = $ChartData [$index];
}
$ChartCenterX = $ChartDiameter/2 + 10;
$ChartCenterY = $ChartDiameter/2 + 10;
Generate Blank Graphics
$image = Imagecreate ($ChartWidth, $ChartHeight);
assigning colors
$colorBody = Imagecolorallocate ($image, 0xFF, 0xFF, 0xFF);
$colorBorder = Imagecolorallocate ($image, 0x00, 0x00, 0x00);
$colorText = Imagecolorallocate ($image, 0x00, 0x00, 0x00);
$colorSlice [] = Imagecolorallocate ($image, 0xFF, 0x00, 0x00);//This is the color corresponding to the array you wrote above
$colorSlice [] = Imagecolorallocate ($image, 0x00, 0xFF, 0x00);
Fill the back border
Imagefill ($image, 0, 0, $colorBody);
Draw every fan
$Degrees = 0;
for ($index = 0; $index < count ($ChartData); $index + +) {
$StartDegrees = round ($Degrees);
$Degrees + = (($ChartData [$index]/$ChartTotal) *360);
$EndDegrees = round ($Degrees);
$CurrentColor = $colorSlice [$index% (count ($colorSlice))];
Drawing F
Imagearc ($image, $ChartCenterX, $ChartCenterY, $ChartDiameter, $ChartDiameter, $StartDegrees, $EndDegrees, $ CurrentColor);
Draw a line
List ($ArcX, $ArcY) = Circle_point ($StartDegrees, $ChartDiameter);
Imageline ($image, $ChartCenterX, $ChartCenterY, floor ($ChartCenterX + $ArcX),
Floor ($ChartCenterY + $ArcY), $CurrentColor);
Draw a line
List ($ArcX, $ArcY) = Circle_point ($EndDegrees, $ChartDiameter);
Imageline ($image, $ChartCenterX, $ChartCenterY, ceil ($ChartCenterX + $ArcX),
Ceil ($ChartCenterY + $ArcY), $CurrentColor);
Fill sector
$MidPoint = Round ((($EndDegrees – $StartDegrees)/2) + $StartDegrees);
List ($ArcX, $ArcY) = Circle_point ($MidPoint, $ChartDiameter/2);
Imagefilltoborder ($image, floor ($ChartCenterX + $ArcX), floor ($ChartCenterY + $ArcY),
$CurrentColor, $CurrentColor);
}
To this script has already had an image of, now need to send it to the browser, it is important to send the hair to the browser, let it know is a GIF file. Otherwise, you can only see a bunch of weird gibberish.
Header ("Content-type:image/png");
Imagegif ($image);
?>

http://www.bkjia.com/PHPjc/825089.html www.bkjia.com true http://www.bkjia.com/PHPjc/825089.html techarticle we will see a number of graphs on a number of web sites, such as the percentage of the three regions or achievements, etc., to introduce a PHP-generated sector percentage of the display process ...

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