JavaScript Editor Javascript source editor     Web programming 



Team LiB
Previous Section Next Section

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 of your arcs add up to 360.

    Team LiB
    Previous Section Next Section


    JavaScript Editor Javascript source editor     Web programming