home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 9 / 09.iso / l / l196 / 3.ddi / PGPIE.BA$ / PGPIE.bin
Encoding:
Text File  |  1990-06-24  |  4.9 KB  |  122 lines

  1. ' PGPIE.BAS:  Create sample pie chart
  2.  
  3. DEFINT A-Z
  4. ' $INCLUDE: 'fontb.BI'
  5. ' $INCLUDE: 'CHRTB.BI'
  6. CONST FALSE = 0, TRUE = NOT FALSE, MONTHS = 12
  7. CONST HIGHESTMODE = 13, TEXTONLY = 0
  8.  
  9. DIM Env AS ChartEnvironment                 ' See CHRTB.BI for declaration of                     ' the ChartEnvironment type
  10. DIM MonthCategories(1 TO MONTHS) AS STRING  ' Array for categories
  11. DIM OJvalues(1 TO MONTHS) AS SINGLE         ' Array for 1st data series
  12. DIM Exploded(1 TO MONTHS) AS INTEGER        ' "Explode" flags array (specifies
  13.                                                                                         '  which pie slices are separated)
  14. DECLARE FUNCTION BestMode ()
  15.  
  16. ' Initialize the data arrays
  17. FOR index = 1 TO MONTHS: READ OJvalues(index): NEXT index
  18. FOR index = 1 TO MONTHS: READ MonthCategories$(index): NEXT index
  19.  
  20. ' Set the elements of the array that determines separation of the pie slices
  21. FOR Flags = 1 TO MONTHS                       ' If value of OJvalues(Flags)
  22.     Exploded(Flags) = (OJvalues(Flags) >= 100)  ' >= 100 the corresponding flag
  23. NEXT Flags                                    ' is set true, separating slices
  24.  
  25. ' Pass the value returned by the BestMode function to the Presentation
  26. ' Graphics routine ChartScreen to set the graphics mode for charting
  27.  
  28. ChartScreen (BestMode)      ' Even if SCREEN is already set to an acceptable
  29.                                                         ' mode, you still have to set it with ChartScreen
  30.  
  31. IF ChartErr = cBadScreen THEN   ' Check to make sure ChartScreen succeeded
  32.     PRINT "Sorry --- There is a screen-mode problem in the Charting library"
  33.     END
  34. END IF
  35.  
  36. ' Initialize a default pie chart
  37.                                                                         ' Pass Env (the environment variable),
  38. DefaultChart Env, cPie, cPercent    ' the constant cPie (for Pie Chart) and
  39.                                                                         ' cPercent (label slices with percentage)
  40.  
  41. ' Add Titles and some chart options. These assignments modify some default
  42. ' values set in the variable Env (of type ChartEnvironment) by DefaultChart
  43.  
  44.  
  45. Env.MainTitle.Title = "Good Neighbor Grocery" ' Specifies text of chart title
  46. Env.MainTitle.TitleColor = 15                 ' Specifies color of title text
  47. Env.MainTitle.Justify = cCenter               ' How to align of title text
  48. Env.SubTitle.Title = "Orange Juice Sales"     ' Text of chart subtitle
  49. Env.SubTitle.TitleColor = 11                  ' Color of subtitle text
  50. Env.SubTitle.Justify = cCenter                ' How to align of subtitle text
  51. Env.ChartWindow.Border = cYes                 ' Specifies chart has no border
  52.  
  53. ' Call the pie-charting routine --- Arguments for call to ChartPie are:
  54. ' Env                 - Environment variable
  55. ' MonthCategories()   - Array containing Category labels
  56. ' OJvalues()          - Array containing Data values to chart
  57. ' Exploded()          - Integer array tells which pieces of the pie should
  58. '                         be separated (non-zero=exploded, 0=not exploded)
  59. ' MONTHS              - Tells number of data values to chart
  60.  
  61.     ChartPie Env, MonthCategories(), OJvalues(), Exploded(), MONTHS
  62.     SLEEP
  63.     '  If the rest of your program isn't graphic, reset original mode here
  64. END
  65.  
  66. ' Simulate data generation for chart values and category labels
  67. DATA 33,27,42,64,106,157,182,217,128,62,43,36
  68. DATA "Jan","Feb","Mar","Apr","May","Jun","Jly","Aug","Sep","Oct","Nov","Dec"
  69.  
  70. '============= Function to determine and set highest resolution ========
  71. ' The BestMode function uses a local error trap to check available modes,
  72. ' then assigns the integer representing the best mode for charting to its
  73. ' name so it is returned to the caller. The function terminate execution if
  74. ' the hardware doesn't support a mode appropriate for Presentation Graphics
  75. '========================================================================
  76. FUNCTION BestMode
  77.  
  78. ' Set a trap for an expected local error --- handled within the function
  79. ON LOCAL ERROR GOTO ScreenError
  80.  
  81. FOR TestValue = HIGHESTMODE TO 0 STEP -1
  82.     DisplayError = FALSE
  83.     SCREEN TestValue
  84.     IF DisplayError = FALSE THEN
  85.         SELECT CASE TestValue
  86.             CASE 12, 13
  87.                 BestMode = 12
  88.             CASE 9, 10, 11
  89.                 BestMode = 9
  90.             CASE 8, 4, 3
  91.                 BestMode = TestValue
  92.             CASE 2, 7
  93.                 BestMode = 2
  94.             CASE 1
  95.                 BestMode = 1
  96.             CASE ELSE
  97.                 PRINT "Sorry, you need graphics to display charts"
  98.                 END
  99.         END SELECT
  100.         EXIT FUNCTION
  101.     END IF
  102. NEXT TestValue
  103. ' Note there is no need to turn off the local error handler. It is turned off
  104. ' automatically when control passes out of the function
  105.  
  106. EXIT FUNCTION
  107. '==================== | Local error handler code |=======================
  108. ' The ScreenError label identifies a local error handler relied in the
  109. ' BestMode function. Invalid SCREEN values generate Error # 5 (Illegal
  110. ' function call) --- so if that is not the error reset ERROR to the ERR
  111. ' value that was generated so the error can be passed to other, possibly
  112. ' more appropriate errors.
  113. ScreenError:
  114.     IF ERR = 5 THEN
  115.         DisplayError = TRUE
  116.         RESUME NEXT
  117.     ELSE
  118.         ERROR ERR
  119.     END IF
  120. END FUNCTION
  121.  
  122.