Getting Fancy with Pie Charts
A little boring, but they introduced you to the process of creating images—define the canvas, define the colors, and then draw and fill.
Use this same sequence of events to expand your scripts to create charts and graphs, using either static or dynamic data for the data points.
Draws a basic pie chart.
<?php
//create the canvas $myImage = ImageCreate(150,150); //set up some colors $white = ImageColorAllocate($myImage, 255, 255, 255); $red = ImageColorAllocate($myImage, 255, 0, 0); $green = ImageColorAllocate($myImage, 0, 255, 0); $blue = ImageColorAllocate($myImage, 0, 0, 255); //draw a pie ImageFilledArc($myImage, 50, 50, 100, 50, 0, 90, $red, IMG_ARC_PIE); ImageFilledArc($myImage, 50, 50, 100, 50, 91, 180 , $green, IMG_ARC_PIE); ImageFilledArc($myImage, 50, 50, 100, 50, 181, 360 , $blue, IMG_ARC_PIE); //output the image to the browser header ("Content-type: image/jpeg"); ImageJpeg($myImage); //clean up after yourself ImageDestroy($myImage); ?>
Out put
which has several attributes:
- The image identifier.
- The partial ellipse centered at x.
- The partial ellipse centered at y.
- The partial ellipse width.
- The partial ellipse height.
- The partial ellipse start point.
- The partial ellipse end point.
- Color.
- Style.
EmoticonEmoticon