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

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