## Constructing a PieChart

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

tellboy
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

### Constructing a PieChart

How do you resolve the issue of arc angles that do not calculate to an integer.

The arc angle of a graphic does not accept anything but integers as can be seen from the image.

You can overcome it by using round but that seems to affect the last segment, particularly when it is only a small value.

dunbarx
VIP Livecode Opensource Backer
Posts: 7019
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

### Re: Constructing a PieChart

Hi.

It does seem from the docs that only integer values of arcAngle are valid. Normally, this is accurate enough, since human beings cannot discern a half degree difference. It looks like you have several radii that have gaps between their neighbors.

In your case, you would want to do one of two things.

1- Manage the arcAngles so that adjacent slices have common radii, that is, all slices use integral arcAngles, but these always overlie their neighbors. This will mean that the widths of some of the slices will need to be adjusted slightly; they will not be perfectly accurate if derived from a count of 360, but should be fine visually, and this is likely the most important thing.

2- Roll your own radii, by drawing line graphics from a common center towards point on a large virtual circle. This will allow finer control of the angle of the line, but you will still have to manage them as before, so they overlie each other. I do not think this should be necessary, though, unless you have lots and lots of very small slices, which will probably not be visually distinguishable in the first place, since one degree is pretty thin.

Craig Newman

tellboy
Livecode Opensource Backer
Posts: 50
Joined: Wed Mar 06, 2013 1:31 pm

### Re: Constructing a PieChart

I have for the moment settled on

Code: Select all

put round(tValue/tTotalValue * 360) into tArcAngle
Then for the next segment

Code: Select all

When I get to the last segment I do:

Code: Select all

if n = tNumOfSegs then
if tStartAngle + tArcAngle < 360 then
put 360 - tStartAngle into tArcAngle
end if
end if
So far it seems OK but I will keep testing.

dunbarx
VIP Livecode Opensource Backer
Posts: 7019
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

### Re: Constructing a PieChart

Hi.

I think I see what you are up to, and it seems like you have the "overlying" of the radii in hand. And closing the last gap back to the start radius as well.

Isn't liveCode great?

Craig