Initializing help system before first use

Drawing a pie chart


Type: Programming
Rating: 2 (easy-medium)
Description: This model defines a subroutine for drawing a pie chart for a given list of data values, with specified center position and radius and a title text.
File(s): pie.mos


pie.mos
(!******************************************************
   Mosel graph examples
   ==================== 

   file pie.mos
   ````````````
   Drawing a pie chart.
   
   Uses functions from the mmsvg library to draw
   a "User graph" in SVG format.
   
   (c) 2017 Fair Isaac Corporation
       Author: S. Heipcke, Jul. 2017, rev. Sep. 2017
*******************************************************!)

model pie
  uses "mmsvg"

  declarations
    NP=8
    PDATA: array(RP:range) of real
    PID: array(RP) of string
  end-declarations

  procedure drawpie(xpos, ypos: integer, rad: integer, data:array(R:range) of real,
                    pids:array(range) of string, msg: text)
    if sum(i in R) data(i)>1 then
      writeln("Incorrect pie data.")
      return
    end-if

    ttl:=0.0
    forall(i in R) do
      svgaddgroup(pids(i),"Pie slice "+i)
      svgsetstyle(SVG_STROKE,SVG_GREY)
      svgsetstyle(SVG_STROKEWIDTH,0.5)
      svgaddpie(pids(i), xpos, ypos, rad, ttl, ttl+data(i))
      ttl+=data(i)
    end-do

    svgaddgroup("msg", "", SVG_GREY)
    svgaddtext(xpos, ypos+rad+20, msg)
    svgsetstyle(svggetlastobj, SVG_TEXTANCHOR, "middle")

   ! Draw the graph 
    svgrefresh
  end-procedure

 ! Some random data and group IDs
  PDATA::(1..8)[0.2, 0.1, 0.12, 0.05, 0.23, 0.13, 0.075, 0.095]
  forall(i in RP) PID(i):="gp"+i

 ! Configure and draw the graphic
  svgsetgraphviewbox(0,0,200,200)
  drawpie(100, 100, 50, PDATA, PID, "Pie chart example")

 ! Optionally save graphic to a file
  svgsave("pie.svg")

 ! Wait for display window to close 
  svgwaitclose("Close browser window to terminate model execution.", 1)

end-model

© 2001-2025 Fair Isaac Corporation. All rights reserved. This documentation is the property of Fair Isaac Corporation (“FICO”). Receipt or possession of this documentation does not convey rights to disclose, reproduce, make derivative works, use, or allow others to use it except solely for internal evaluation purposes to determine whether to purchase a license to the software described in this documentation, or as otherwise set forth in a written software license agreement between you and FICO (or a FICO affiliate). Use of this documentation and the software described in it must conform strictly to the foregoing permitted uses, and no other use is permitted.