Think of something that you wish Authorware could do but it doesn't?
Let the our good friends at Macromedia know via the wishlist.
Please let us know if you find
any of the materials on this site inappropriate or offensive. Please include
the url and why the material should be reviewed.
Comments and questions about the site are also welcome. Please no Authorware
questions, use the AWARE
list.
|
Back
B1005 - How can I use Authorware variables and functions to create a pie chart?
by - Joseph Ganci
I am working on a project that needs to draw or look like it's filling in a pie chart. Here are the facts: I will have three numbers to work with: say 25, 35, 40 (these would be percentages
that would be used to determine where the dividing lines would be in the chart,
they would equal 100 %).
Can I get Authorware to fill in the pie chart and show the dividing lines within
the chart using some function and or variables?
If you are using Authorware 4.0 or later in Windows, you can use the included
ActiveX control to create a really nice pie chart. However, this example
has the benefit of being cross-platform and internal to Authorware.
Here's code that will
plot a circle and the angles you specify. It will fill in the circle with
a color.
orgx := 200
orgy := 200
radius := 150
percentages := "25,50,25"
num_angles := LineCount(percentages,",")
SetFill(TRUE, RGB(0,255,0))
Circle(1,orgx-radius,orgy-radius,orgx+radius,orgy+radius)
repeat with i := 1 to num_angles
percentage := GetLine(percentages,i,i,",")
angle := (((50 - (percentage+total)) * Pi / 50))
total := total + percentage
x := SIN(angle) * radius
y := COS(angle) * radius
Line(4, orgx,orgy,orgx+x,orgy+y)
end repeat
The first two lines determine the x and y pixel on the screen for the center
of the circle. The next line determines how long to make the radius of the circle.
You can place any combination of angles into "percentages", each divided by a
comma. Make sure they equal 100 for accurate results.
The next three lines determine the number of slices and create a circle of the
indicated center and radius and fill it with green.
The repeat loop then plots each slice using the Line function.
Update Note: But that's not all! I received
the following email from Alden Erickson: Recently, the aware list was asked
if it was possible to create a multicolored pie chart in Authorware. The
code on your site was cited as a good example. I have modified your code
and added the capability of multiple colors to the slices. I am including
a copy of it below. Thanks for the excellent example.
He kindly sent me his source code. Download the code from the Download area
There are 0 reviews
Add your review
Back
|