Getting Fancy with Pie Charts
The previous examples were a little boring, but they introduced you to the process of creating images—define the canvas, define the colors, and then draw and fill. You can 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. Listing 13.3 draws a basic pie chart.
Listing 13.3. A Basic Pie Chart
1: <? 2: //create the canvas 3: $myImage = ImageCreate(150,150); 4: 5: //set up some colors 6: $white = ImageColorAllocate($myImage, 255, 255, 255); 7: $red = ImageColorAllocate($myImage, 255, 0, 0); 8: $green = ImageColorAllocate($myImage, 0, 255, 0); 9: $blue = ImageColorAllocate($myImage, 0, 0, 255); 10: 11: //draw a pie 12: ImageFilledArc($myImage, ... |
Get Sams Teach Yourself PHP, MySQL® and Apache All in One now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.