making a pie chart

Malte Brill malte.brill at t-online.de
Mon Nov 11 07:23:00 EST 2002


Hi Yves:
Here is my two cent (just very rough, coded "on the fly":

Put the following in the card skript
on newGraphic
  choose browse tool
end newGraphic

Button "a":

global numberOfSlices,percentage,allValues,other
on mouseup
  put 0 into other
  put 0 into allValues
  put 0 into numberOfSlices
  put 10 into percentage[1]
  put 20 into percentage[2]
  put 30 into percentage[3]
repeat for each element x in percentage
   put x+allValues into allValues
   put numberOfSlices+1 into numberOfSlices
end repeat
if allValues<100 then put 100-allValues into other
end mouseup

--Just to initialize the values

Button "b":

global numberOfSlices,percentage,allValues,other,angleOffset
on mouseUp
  put 0 into angleOffset
  repeat with i=1 to numberOfSlices
    create graphic ("slice"&i)
    set the style of graphic (slice&i) to oval
    set the rectangle of graphic(slice&i) to 0,0,100,100
    set the arcAngle of graphic(slice&i) to percentage[i]*3.6
    set the startangle of graphic (slice&i) to angleoffset
    put angleoffset+percentage[i]*3.6 into angleOffset
  end repeat
 if other >0 then
  create graphic "others"
  set the style of graphic "others" to oval
  set the rectangle of graphic others to 0,0,100,100
  set the arcangle of graphic"others" to other*3.6
  set the startangle of graphic "others" to angleOffset
 end if
end mouseUp

Regards
Malte




More information about the use-livecode mailing list