PHP to make pie chart function (turn)

Source: Internet
Author: User
Tags array border color count net return
Pie chart | function php to make pie chart function
Author: Qdlover Released Date: September 15, 2000 reading: 14
--------------------------------------------------------------------------------

Introduce myself again, hehe
I am a novice, when learning PHP is purely to cope with leadership oh, let us do a statistical map, I was learning ASP, suddenly diverted very not adapt, but the PHP function is really very powerful ah, oh, I can not leave him, this is not, pie chart, column chart are all done, but there are many problems I will not, but also hope that we have more advice And said a lot of crap, I thought it was a letter.
My contact method is:
Email:qingdaohb@yeah.net
Http://qdlover.yeah.net
The boss urged, no way, pie chart function out of the oven, everyone rob Ah

########
Bimage.php3
########
?
/*
Function description
$chartdata: Data, is an array element
$chartfont: Font Size
$chartdiameter: Determine the size of the cake (to see you hungry, hehe)
$chartlabel: Title, also an array element
$colorslice: array of colors, such as $tmp=array255,255,255); $colorslic =array ($tmp);
$colorborder: Border color, array
$colortext: text color, array
$colorbody: Background color, array
$file: Output Picture file name * *
function Bimage ($chartdata,
$chartfont,
$chartdiameter,
$chartlabel,
$colorslice,
$colorbody,
$colorborder,
$colortext,
$file
)
{
$chartdiameter = 150;

$chartfontheight =imagefontheight ($chartfont);
$d 1=10; $d 2=20; $d 3=30; $d 4=40; $d 5=50;
$chartdata =array ($d 1, $d 2, $d 3, $d 4, $d 5);
$chartlabel =array ("D1", "D2", "D3", "D4", "D5");
$chartwidth = $chartdiameter +20;
$chartheight = $chartdiameter +20+ (($chartfontheight +2) *count ($chartdata));
Header ("Content-type:image/gif");
$image =imagecreate ($chartwidth, $chartheight);
$colorbody =imagecolorallocate ($image, $colorbody [0], $colorbody [1], $colorbody [2]);
$colortext =imagecolorallocate ($image, $colortext [0], $colortext [1], $colortext [2]);
$colorborder =imagecolorallocate ($image, $colorborder [0], $colorborder [1], $colorborder [2]);
for ($i =0; $i <count ($colorslice); $i + +)
{
$t =imagecolorallocate ($image, $colorslice [$i][0], $colorslice [$i][1], $colorslice [$i][2]);
$colorslice [$i]= $t;
}




for ($i =0; $i <count ($chartdata); $i + +)
{
$charttotal + + $chartdata [$i];
}
$chartcenterx = $chartdiameter/2+10;
$chartcentery = $chartdiameter/2+10;
$degrees = 0;
for ($i =0; $i <count ($chartdata); $i + +)
{
$startdegrees =round ($degrees);
$degrees + + ($chartdata [$i]/$charttotal) *360);
$enddegrees =round ($degrees);
$currentcolor = $colorslice [$i% (count ($colorslice))];
Imagearc ($image,
$chartcenterx,
$chartcentery,
$chartdiameter,
$chartdiameter,
$startdegrees,
$enddegrees,
$currentcolor);
List ($ARCX, $arcy) =circle_point ($startdegrees, $chartdiameter);

Imageline ($image,
$chartcenterx,
$chartcentery,
Floor ($chartcenterx + $ARCX),
Floor ($chartcentery + $arcy),
$currentcolor);
List ($ARCX, $arcy) =circle_point ($enddegrees, $chartdiameter);

Imageline ($image,
$chartcenterx,
$chartcentery,
Ceil ($chartcenterx + $ARCX),
Ceil ($chartcentery + $arcy),
$currentcolor);

$midpoint =round (($enddegrees-$startdegrees)/2) + $startdegrees);
List ($ARCX, $arcy) = Circle_point ($midpoint, $chartdiameter/2);
Imagefilltoborder ($image,
Floor ($chartcenterx + $ARCX),
Floor ($chartcentery + $arcy),
$currentcolor,
$currentcolor);
}
Imagearc ($image,
$chartcenterx,
$chartcentery,
$chartdiameter,
$chartdiameter,
0,360,
$colorborder);
Imagefilltoborder ($image,
Floor ($chartcenterx + ($chartdiameter/2) +2),
$chartcentery,
$colorborder,
$colorborder);
for ($i =0; $i <count ($chartdata); $i + +)
{
$currentcolor = $colorslice [$i% (count ($colorslice))];
$liney = $chartdiameter +20+ ($i * ($chartfontheight +2));
Imagerectangle ($image,
10,
$liney,
20+ $chartfontheight,
$liney + $chartfontheight,
$colorbody);
Imagefilltoborder ($image,
12,
$liney +2,
$colorbody,
$currentcolor);
Imagestring ($image,
$chartfont,
40+ $chartfontheight,
$liney,
"$chartlabel [$i]: $chartdata [$i]",
$colortext);

}


Imagegif ($image, $file);

}

function radians ($degrees)
{
Return ($degrees * (pi ()/180.0));
}
function Circle_point ($degrees, $diameter)
{
$x =cos (radians ($degrees)) * ($diameter/2);
$y =sin (radians ($degrees)) * ($diameter/2);
Return (Array ($x, $y));
}
?>
###########
This is an example of a call
###########

?
Include ("bfunc.php3");
$chartdiameter = 250;
$chartfont = 5;
$d 1=10; $d 2=20; $d 3=30; $d 4=40; $d 5=50;
$chartdata =array ($d 1, $d 2, $d 3, $d 4, $d 5);
$chartlabel =array ("D1", "D2", "D3", "D4", "D5");

$colorbody =array (0XFF,0XFF,0XFF);
$colorborder =array (0x00,0x00,0x00);
$colortext =array (0XFF,0XFF,0XFF);

$color 1=array (0xff,0x00,0x00);
$color 2=array (0x00,0xff,0x00);
$color 3=array (0X00,0X00,0XFF);
$color 4=array (0xff,0xff,0x00);
$color 5=array (0XFF,0X00,0XFF);
$colorslice =array ($color 1, $color 2, $color 3, $color 4, $color 5);
$file = "Tj.gif"
Bimage ($chartdata,
$chartfont,
$chartdiameter,
$chartlabel,
$colorslice,
$colorbody,
$colorborder,
$colortext,
$file)
?>


"Austrian cable network copyright, if necessary reprint, please indicate the source"


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.