QA


Q&A

Q

How do I use dynamic data to create the slices of a pie chart?

A

When creating any image, the start points and drawing lengths do not need to be statically indicatedthey 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°:

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 or database queries in your script. Be sure to add code to verify that all your arcs add up to 360.




Sams Teach Yourself PHP, MySQL And Apache All in One
Sams Teach Yourself PHP, MySQL and Apache All in One (3rd Edition)
ISBN: 0672328739
EAN: 2147483647
Year: 2004
Pages: 327

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net