making a pie chart

Richard Gaskin ambassador at fourthworld.com
Mon Nov 11 07:17:01 EST 2002


yves COPPE wrote:

> I have a list of ages with percent :
> 
> 0-10 : 15
> 11-20 : 20
> 21-30 : 17
> ...
> 
> 
> does anyone know the script how to make a pie chart with this suite of data ?


on mouseUp
  put fld 1 into tData
  put "20,20,120,120" into tRect
  put "blue,green,red,yellow,purple,orange,gray" into tColors
  --
  MakePieChart tData, tRect, tColors
end mouseUp

on MakePieChart pData, pRect, pColors
  lock screen
  -- Set up template object:
  set the style of the templategraphic to "oval"
  set the rect of the templategraphic to pRect
  set the filled of the templategraphic to true
  --
  -- Create legend field:
  create field "PieLegend"
  put it into tLegendField
  set the showborder of tLegendField to false
  set the locktext of tLegendField to true
  set the traversalon of tLegendField to false
  --
  -- Create pie slices:
  put 0 into tCounter
  put empty into tNuObj
  repeat for each line tLine in pData
    add 1 to tCounter
    if tNuObj is not empty then put tNuObj into tOldObj
    create grc
    put it into tNuObj
    set the arcAngle of tNuObj to (360 * (last word of tLine/100) )
    if tCounter > 1 then
      set the startAngle of tNuObj to (the arcAngle of tOldObj)+(the
startAngle of tOldObj)
    end if
    put item tCounter of pColors into tColor
    set the backgroundcolor of tNuObj to tColor
    -- Make legend entry:
    put "      "&word 1 of tLine into line tCounter of field "PieLegend"
    set the backgroundcolor of char 1 to 4 of line tCounter of field
"PieLegend" to tColor
  end repeat
  -- Position legecd field:
  set the height of field "PieLegend" to the formattedheight of tLegendField
  set the topleft of field "PieLegend" to the topright of grc 1
  choose browse tool
  unlock screen
end MakePieChart


-- 
 Richard Gaskin 
 Fourth World Media Corporation
 Developer of WebMerge 2.0: Publish any database on any site
 ___________________________________________________________
 Ambassador at FourthWorld.com       http://www.FourthWorld.com
 Tel: 323-225-3717                       AIM: FourthWorldInc




More information about the use-livecode mailing list