                 Chapter 10: Business Graphics

This chapter  presents  business graphic routines  to create
bar graphs and pie charts.

10.1 Bar Graphs

                            B A R S

BARS plots bar graphs.

The call is:  CALL BARS (XRAY, Y1RAY, Y2RAY, N)   level 2, 3

XRAY          is an array of  user coordinates  defining the
              position of the bars on the X-axis.
Y1RAY         is an array of user coordinates containing the
              start points of the bars on the Y-axis.
Y2RAY         is an array of user coordinates containing the
              end points of the bars on the Y-axis.
N             is the number of bars.

Notes:     -  Shading patterns of bars can be selected  with
              SHDPAT or MYPAT. Shading  numbers will be  in-
              cremented by 1 after every call to BARS.
           -  Legends can be plotted for bar graphs.

The following routines modify the appearance of bar graphs.

                         B A R T Y P

The routine BARTYP defines vertical or horizontal bars.

The call is:  CALL BARTYP (CTYP)               level 1, 2, 3

CTYP          is a character string defining the bar type.
   = 'VERT'   means that vertical bars will be plotted.
   = 'HORI'   means that horizontal bars will be plotted. If
              this parameter is used, XRAY defines the posi-
              tion of the bars on the Y-axis while Y1RAY and
              Y2RAY define  the position  of the bars on the
              X-axis.
                                     Default: CTYP = 'VERT'.

                         B A R W T H

BARWTH defines the width of the bars.
The call is:  CALL BARWTH (XWTH)               level 1, 2, 3

XWTH          is a real number  defining the width.  If XWTH
              is positive, the bar width is the absolute va-
              lue of   XWTH * (XRAY(1)-XRAY(2)).  If XWTH is
              negative, the absolute value of  XWTH is  used
              where XWTH must be specified in plot coordina-
              tes.
                                        Default: XWTH = 0.75

                         B A R P O S

The position  of the  bars is  determined  by the parameters
XRAY, Y1RAY  and Y2RAY.  The routine  BARPOS  can be used to
select predefined positions. The parameters  XRAY, Y1RAY and
Y2RAY will contain the calculated positions.

The call is:  CALL BARPOS (COPT)               level 1, 2, 3

COPT          is a character string that defines the positi-
              on of the bars.
  = 'NONE'    means that  the positions  are defined only by
              the parameters in BARS.
  = 'TICKS'   means  that the bars  will be centred at major
              ticks. XRAY must be a dummy vector.
  = 'AXIS'    means that  vertical bars start at the  X-axis
              and horizontal bars at the Y-axis.  Y1RAY must
              be a dummy vector.
  = 'BOTH'    activates the options 'TICKS' and 'AXIS'. XRAY
              and Y1RAY must be dummy arrays.
                                     Default: COPT = 'NONE'.

Bars can be  plotted on top of  one another  if the  routine
BARS is called several times.  To plot bars  side by side in
groups, the routine BARGRP can be used.

                         B A R G R P

The routine  BARGRP  puts bars with  the same  axis position
into groups. The number of group elements should be the same
as the number of calls to the routine BARS.

The call is:  CALL BARGRP (NGRP, GAP)          level 1, 2, 3

NGRP          is the number of bars defining one group.
GAP           defines the spacing between group bars. If GAP
              is positive, the value GAP * W is used where W
              is the width of a single bar.  If GAP is nega-
              tive, the positive value of GAP  is used where
              GAP must be specified in plot coordinates.

                         L A B E L S

The routine LABELS defines labels for bar graphs.

The call is:  CALL LABELS (CLAB, 'BARS')       level 1, 2, 3

CLAB          is a character defining the labels.
   = 'NONE'   means that no labels will be plotted.
   = 'SECOND' means that Y2RAY is used for labels.
   = 'FIRST'  means that Y1RAY is used for labels.
   = 'DELTA'  means  that  the  difference  vector  (Y2RAY -
              Y1RAY) is used for labels.
                                     Default: CLAB = 'NONE'.

                         L A B P O S

The routine LABPOS defines the position of the labels.

The call is:  CALL LABPOS (CPOS, 'BARS')       level 1, 2, 3

CPOS          is a character string that defines the positi-
              on of the labels.
 = 'INSIDE'   means inside at the end of a bar.
 = 'OUTSIDE'  means outside at the end of a bar.
 = 'LEFT'     defines the upper left side.
 = 'RIGHT'    defines the upper right side.
 = 'CENTER'   selects the centre of a bar.
 = 'AUTO'     means  'INSIDE' if labels are smaller than the
              bar width, otherwise 'OUTSIDE'.
                                     Default: CPOS = 'AUTO'.

                         D I G I T S

The routine  DIGITS  defines the number of decimal places in
the labels.

The call is:  CALL DIGITS (NDIG, 'BARS')       level 1, 2, 3

NDIG          is the number of decimal places (>= -1).
                                           Default: NDIG = 1

10.2 Pie Charts

                         P I E G R F

PIEGRF plots pie charts.

The call is:  CALL PIEGRF (CBUF, NLIN, XRAY, NSEG)   level 1

CBUF          is a  character string  containing  text lines
              for segment labels.  More than one line can be
              defined for labels.  CBUF must be created with
              LEGLIN after calling LEGINI.  If NLIN is 0  in
              the parameter list,  CBUF can be a dummy vari-
              able.
NLIN          is the number of text lines  used for one seg-
              ment label.
XRAY          is an array of user coordinates.
NSEG          is the dimension of XRAY.

Notes:     -  The centre  and the  size of  pies is  defined
              by a region  that can be changed with the rou-
              tines AXSPOS and AXSLEN.
           -  PIEGRF sets the level to 2. Titles and legends
              can be plotted after PIEGRF is called.
           -  Segment labels  can  contain several  lines of
              text and  the data values specified in PIEGRF.
              Data values  can also  be converted to percent
              values.
           -  Segment  labels  are  contained  within  a box
              where the thickness of the border can be chan-
              ged with FRAME.

The following routines modify the appearance of pie charts.

                         C H N P I E

CHNPIE defines colours and shading patterns for pie graphs.

The call is:  CALL CHNPIE (CATT)               level 1, 2, 3

CATT          is a character string  defining segment attri-
              butes.
  = 'NONE'    means that  all  pie segments  will be plotted
              with the current colour and shading pattern.
  = 'COLOR'   means that every segment will have a different
              colour.
  = 'PATTERN' means that every segment will have a different
              shading pattern.
  = 'BOTH'    means that every segment will have both a dif-
              ferent colour and shading pattern.
                                  Default: CATT = 'PATTERN'.

Note:         The sequence of colours is:  WHITE/BLACK, RED,
              GREEN, YELLOW, BLUE, ORANGE, CYAN, MAGENTA.
              The sequence of shading patterns is 0 - 17.
              Colour and  pattern cycles can be changed with
              CLRCYC and PATCYC.

                         L A B E L S

LABELS selects  data or percent values  used for segment la-
bels.

The call is:  CALL LABELS (CLAB, 'PIE')        level 1, 2, 3

CLAB          is a character string that defines  the values
              used for segment labels.
  = 'NONE'    means that data values will not be displayed.
  = 'PERCENT' means that values will be plotted as percenta-
              ges.
  = 'DATA'    means that the data values specified in PIEGRF
              will be plotted.
  = 'BOTH'    means both 'PERCENT' and 'DATA'.
                                  Default: CDOC = 'PERCENT'.

                         L A B P O S

LABPOS determines the position of segment labels.

The call is:  CALL LABPOS (CPOS, 'PIE')        level 1, 2, 3

CPOS          is a character string defining the position of
              labels.
 = 'INTERNAL' means that  labels will  be plotted inside pie
              segments.  If labels are too big, they will be
              plotted outside.
 = 'EXTERNAL' means that segment labels will be plotted out-
              side pie segments.
 = 'ALIGNED'  means that segment labels will be plotted out-
              side pie segments and aligned.
                                 Default: CPOS = 'INTERNAL'.

                         L A B T Y P

LABTYP defines the position of text lines in segment labels.

The call is:  CALL LABTYP (CTYP, 'PIE')        level 1, 2, 3

CTYP          is a  character string  that defines  how text
              lines are justified.
 = 'CENTER'   centres text lines.
 = 'LEFT'     left-justifies text lines.
 = 'RIGHT'    right-justifies text lines.
 = 'OUTWARDS' left-justifies text lines on the  left side of
              pies  and right-justifies  text  lines  on the
              right side of pies.
  = 'INWARDS' right-justifies text lines on the left side of
              pies  and  left-justifies  text  lines  on the
              right side of pies.
                                   Default: CTYP = 'CENTER'.

                         D I G I T S

The routine DIGITS defines the number of decimal places used
in segment labels.

The call is:  CALL DIGITS (NDIG, CDIG)         level 1, 2, 3

NDIG          is the number of decimal places (>= -1).
CDIG          is a  character string  selecting the data va-
              lues.
  = 'PIE'     defines the number of  decimal places used for
              percent and data values.
  = 'PERCENT' defines the number of decimal places  used for
              percent values.
  = 'DATA'    defines the number of decimal places  used for
              data values.
                                        Default: (1, 'PIE').

                         P I E L A B

The routine  PIELAB  defines character strings  that can  be
plotted on the left or right side of data values within seg-
ment labels.

The call is:  CALL PIELAB (CLAB, CPOS)         level 1, 2, 3

CLAB          is a character string displayed in segment la-
              bels.
CPOS          is a character string that defines the positi-
              on of CLAB.
  = 'LEFT'    means that  CLAB  will be plotted  on the left
              side of data values.
  = 'RIGHT'   means that  CLAB will be plotted  on the right
              side of data values.

Note:         If percent and data values are plotted in seg-
              ment labels,  PIELAB is only used for data va-
              lues.

                         P I E E X P

Pie segments will be offset by 8% of the radius if PIEEXP is
called.

The call is:  CALL PIEEXP                      level 1, 2, 3

Note:         Single segments  will be offset if the corres-
              ponding values in PIEGRF are negative.

                         P I E V E C

PIEVEC modifies the arrows plotted between segments  and la-
bels that lie outside of segments.

The call is:  CALL PIEVEC (IVEC, COPT)         level 1, 2, 3

IVEC          defines the arrow head (see VECTOR).
COPT          is a character string  that defines the vector
              plotted between segments and labels.
 = 'NONE'     suppresses vectors.
 = 'STRAIGHT' means that straight vectors will be plotted.
 = 'BROKEN'   means that broken vectors will be plotted.
                                  Default: (2301, 'BROKEN').

                         U S R P I E

USRPIE is a  user-defined  subroutine  that can  modify  pie
charts such as suppressing certain labels.  USRPIE is called
by PIEGRF for each segment.

The call is:  CALL USRPIE (ISEG,  XDAT,  XPER,  NRAD,  NOFF,
                 ANGLE, NVX, NVY, IDRW, IANN)  level 1, 2, 3

ISEG          is the segment index (starting with 1).
XDAT          is the data value  of the segment as specified
              in PIEGRF.
XPER          is the percent value of XDAT.
NRAD          is the segment radius in plot coordinates.
NOFF          is the segment offset in plot coordinates (de-
              fault: 0).
ANGLE         is the offset angle measured  in degrees  in a
              counter-clockwise direction. The default value
              is the angle which bisects the segment.
NVX, NVY      shifts  the  segment label  in the  X-  and Y-
              direction by NVX and NVY plot coordinates.
IDRW          defines the plotting of segments. If IDRW = 0,
              plotting will be suppressed (default: 1).
IANN          defines the  plotting of labels.  If IANN = 0,
              labels will be suppressed (default: 1).

Note:         The  first  3 parameters of  USRPIE  are  only
              given for information and cannot be changed by
              the user.


10.3 Examples

            PROGRAM EX10_1   !  Bar Graphs
            DIMENSION X(9),Y(9),Y1(9),Y2(9),Y3(9)
            CHARACTER*60 CTIT,CBUF*24

            DATA  X/1.,2.,3.,4.,5.,6.,7.,8.,9./ Y/9*0./
           *     Y1/1.,1.5,2.5,1.3,2.0,1.2,0.7,1.4,1.1/
           *     Y2/2.,2.7,3.5,2.1,3.2,1.9,2.0,2.3,1.8/
           *     Y3/4.,3.5,4.5,3.7,4.,2.9,3.0,3.2,2.6/

            NYA=2700
            CTIT='Bar graphs (BARS)'

            CALL SETPAG('DA4P')
            CALL DISINI
            CALL PAGERA
            CALL COMPLX
            CALL TICKS(1,'X')
            CALL INTAX
            CALL AXSLEN(1600,700)
            CALL TITLIN(CTIT,3)

            CALL LEGINI(CBUF,3,8)
            CALL LEGLIN(CBUF,'FIRST',1)
            CALL LEGLIN(CBUF,'SECOND',2)
            CALL LEGLIN(CBUF,'THIRD',3)
            CALL LEGTIT(' ')

            CALL SHDPAT(5)
            DO I=1,3
              IF(I.GT.1) CALL LABELS('NONE','X')
              CALL AXSPOS(300,NYA-(I-1)*800)

              CALL GRAF(0.,10.,0.,1.,0.,5.,0.,1.)

              IF(I.EQ.1) THEN
                CALL BARGRP(3,0.15)
                CALL BARS(X,Y,Y1,9)
                CALL BARS(X,Y,Y2,9)
                CALL BARS(X,Y,Y3,9)
                CALL RESET('BARGRP')
              ELSE IF(I.EQ.2) THEN
                CALL HEIGHT(30)
                CALL LABELS('DELTA','BARS')
                CALL LABPOS('CENTER','BARS')
                CALL BARS(X,Y,Y1,9)
                CALL BARS(X,Y1,Y2,9)
                CALL BARS(X,Y2,Y3,9)
                CALL HEIGHT(36)
              ELSE IF(I.EQ.3) THEN
                CALL LABELS('SECOND','BARS')
                CALL LABPOS('OUTSIDE','BARS')
                CALL BARS(X,Y,Y1,9)
              END IF

              IF(I.NE.3) CALL LEGEND(CBUF,7)

              IF(I.EQ.3) THEN
                CALL HEIGHT(50)
                CALL TITLE
              END IF

              CALL ENDGRF
            END DO

            CALL DISFIN
            END


            PROGRAM EX10_2     !  Pie Charts
            DIMENSION XRAY(5)
            CHARACTER*60 CTIT,CBUF*40
            DATA XRAY/1.,2.5,2.,2.7,1.8/

            CTIT='Pie charts (PIEGRF)'
            NYA=2800

            CALL SETPAG('DA4P')
            CALL DISINI
            CALL PAGERA
            CALL COMPLX
            CALL AXSLEN(1600,1000)
            CALL TITLIN(CTIT,2)

            CALL LEGINI(CBUF,5,8)
            CALL LEGLIN(CBUF,'FIRST',1)
            CALL LEGLIN(CBUF,'SECOND',2)
            CALL LEGLIN(CBUF,'THIRD',3)
            CALL LEGLIN(CBUF,'FOURTH',4)
            CALL LEGLIN(CBUF,'FIFTH',5)

      C     Selecting shading patterns
            CALL PATCYC(1,7)
            CALL PATCYC(2,4)
            CALL PATCYC(3,13)
            CALL PATCYC(4,3)
            CALL PATCYC(5,5)

            DO I=1,2
              CALL AXSPOS(250,NYA-(I-1)*1200)
              IF(I.EQ.2) THEN
                CALL LABELS('DATA','PIE')
                CALL LABPOS('EXTERNAL','PIE')
              END IF

              CALL PIEGRF(CBUF,1,XRAY,5)

              IF(I.EQ.2) THEN
                CALL HEIGHT(50)
                CALL TITLE
              END IF
              CALL ENDGRF
            END DO
            CALL DISFIN
            END
