home *** CD-ROM | disk | FTP | other *** search
/ Corel Draw 6 / corel-draw-6-cd1.iso / draw / chart.csc < prev    next >
Text File  |  1995-08-18  |  3KB  |  85 lines

  1. REM A Bar Chart will be created in Draw using chartdat.txt
  2. REM Chart.csc 24 July, 1995
  3. REM Actual Data is taken from chartdat.txt, generated if doesn't exist
  4. REM The error handler uses a randomizer to generate the text file.
  5. REM If you replace the text file (Chartdat.txt) with a properly formatted
  6. REM Text file, you can make a chart of whatever data is in that text file.
  7.  
  8. Width = FROMINCHES(.5)        ' thickness of a bar
  9. Gap = FROMINCHES (0.2)        ' gap between bars
  10. Offset = FROMINCHES(.1)        ' offset for the shadow
  11. OriginX = FROMINCHES(-4)        ' origin of the chart
  12. OriginY = FROMINCHES(-5)
  13. GraphRangeX = FROMINCHES(8)    ' range of the chart
  14. GraphRangeY = FROMINCHES(10)
  15.  
  16. WITHOBJECT DRAW
  17.     ' create a new file and set visible just in case draw isn't up
  18.     .FileNew
  19.     .SetVisible 1
  20.     ' draw x, y axes
  21.     .BeginDrawCurve OriginX, OriginY + GraphRangeY
  22.     .DrawCurveLineTo OriginX, OriginY
  23.     .DrawCurveLineTo OriginX + GraphRangeX, OriginY
  24.     .EndDrawCurve
  25.     .SetOutlineColor 5, 0, 0, 0, 0            ' Black
  26.  
  27.     ' open data file for input
  28.     ON ERROR GOTO OnOpenError                    ' trap error : file not found?
  29.         OPEN "chartdat.txt" for input as 1
  30.     ON ERROR EXIT                                ' No more trapping errors
  31.     INPUT #1, NumBars&, Range&, Cutoff&            ' first line in file
  32.     Cutoff = Cutoff/Range * GraphRangeY
  33.  
  34.     For i = 0 To NumBars-1
  35.  
  36.         INPUT #1, Height&                ' indicates height (0-100)
  37.         Height = Height/Range * GraphRangeY
  38.         Leftx = OriginX + i * (Width + Gap) + Gap
  39.         Top = Height + OriginY
  40.  
  41.         ' draw the shadow first : use offset
  42.         .CreateRectangle Top - Offset, Leftx + Offset, Top-Height, Leftx+Width + Offset, 0
  43.         .ApplyUniformFillcolor 5, 100, 100, 100, 0
  44.  
  45.         ' draw the foreground : use different colors
  46.          .CreateRectangle Top, Leftx, Top-Height, Leftx+Width, 0
  47.          IF Height > Cutoff THEN
  48.              .ApplyUniformFillcolor 5, 255, 0, 255, 0
  49.          ELSE
  50.              .ApplyUniformFillcolor 5, 175, 0, 255, 0
  51.          END IF
  52.  
  53.     Next i
  54.     
  55.     ' draw cut off line
  56.     .BeginDrawCurve OriginX, Cutoff + OriginY
  57.     .DrawCurveLineTo OriginX + GraphRangeX, Cutoff + OriginY
  58.     .EndDrawCurve
  59.     .ApplyOutline 254, 4, 0, 0, 100, 0, 9, 0, 0, 0
  60.     .SetOutlineColor 5, 100, 100, 100, 0
  61.     .OrderToBack
  62.  
  63.     close #1
  64.     STOP                     ' so that we don't execute the error handler!!
  65.  
  66. OnOpenError :
  67.     ' the file did not exist, so create one
  68.     IF ERRNUM = 201 THEN
  69.         ErrMsg$ = "Data File chartdat.txt does not exist" + chr(13)
  70.         ErrMsg$ = ErrMsg$ + "Do you want one to be created?"
  71.         ret% = MESSAGEBOX (ErrMsg$,"Error Handling", 4+32)
  72.         IF ret% = 7 THEN STOP
  73.         OPEN "chartdat.txt" FOR OUTPUT AS 2
  74.         RANDOMIZE
  75.         PRINT #2, "10, 200, 100"
  76.         FOR i = 1 to 10
  77.             PRINT #2, RND(200)
  78.         NEXT i
  79.         CLOSE #2
  80.         RESUME
  81.     END IF
  82.  
  83. END WITHOBJECT
  84.  
  85.