Q&A

Q1:How do I use dynamic data to create the slices of a pie chart?
A1: When creating any image, the start points and drawing lengths do not need to be statically indicated—they can be variables whose values are determined by a database, user input, or calculations within the script. For example, this code creates a red, filled arc of 90[dg]:
ImageFilledArc($myImage, 50, 50, 100, 50, 0, 90, $red, IMG_ARC_PIE);

You could set this up so that the red filled arc at the top of the pie will hold the percentage of the total for May Sales in a variable called $may_sales_pct. The line then becomes something like this:

ImageFilledArc($myImage, 50, 50, 100, 50, 0, $may_sales_pct, $red, IMG_ARC_PIE);

The number then is filled in from the calculations ...

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.