HyperCard: Script for Drawing Pie Charts (7/92)

This handler draws a pie chart when you pass it some values.
Try this: pieChart "3,4,5,6,7,8"

To erase the chart, type "clearPicture".

if frame is empty
then put insetRect(localRect(rect of card window),10) into frame
clearPicture frame
put itemArray(values) into values -- convert to comma separated list
put sum(values) into total
put number of items in values into valueCount
put item 3 of frame - item 1 of frame into frameWidth
put item 4 of frame - item 2 of frame into frameHeight
put min(frameWidth,frameHeight)/2 into radius
reset paint
get centerOfRect(frame)
put item 1 of it into centerH
put item 2 of it into centerV
choose oval tool
set lineSize to 2
set centered to true
drag from centerH,centerV to ┬
round(centerH+radius),round(centerV+radius)
choose line tool
set centered to false
drag from centerH,centerV to centerH,round(centerV-radius)
put zero into angle
repeat with i = 1 to valueCount
put pi * item i of values / total into halfChange
add halfChange to angle
put centerH + round((radius-3) * sin(angle)) into halfH
put centerV - round((radius-3) * cos(angle)) into halfV
add halfChange to angle
put centerH + round(radius * sin(angle)) into h
put centerV - round(radius * cos(angle)) into v
choose line tool
drag from centerH,centerV to h,v
if halfChange > .01 then -- don't try to fill very small wedges
set pattern to item (i mod 12)+1 of "2,13,11,3,14,6,21,17,31,18,4,32"
choose bucket tool
click at halfH, halfV
end if
end repeat
choose browse tool
end pieChart


This article is adapted from the Claris Tech Info database.
Published Date: Feb 19, 2012