home *** CD-ROM | disk | FTP | other *** search
- REM A Bar Chart will be created in Draw using chartdat.txt
- REM Chart.csc 24 July, 1995
- REM Actual Data is taken from chartdat.txt, generated if doesn't exist
- REM The error handler uses a randomizer to generate the text file.
- REM If you replace the text file (Chartdat.txt) with a properly formatted
- REM Text file, you can make a chart of whatever data is in that text file.
-
- Width = FROMINCHES(.5) ' thickness of a bar
- Gap = FROMINCHES (0.2) ' gap between bars
- Offset = FROMINCHES(.1) ' offset for the shadow
- OriginX = FROMINCHES(-4) ' origin of the chart
- OriginY = FROMINCHES(-5)
- GraphRangeX = FROMINCHES(8) ' range of the chart
- GraphRangeY = FROMINCHES(10)
-
- WITHOBJECT DRAW
- ' create a new file and set visible just in case draw isn't up
- .FileNew
- .SetVisible 1
- ' draw x, y axes
- .BeginDrawCurve OriginX, OriginY + GraphRangeY
- .DrawCurveLineTo OriginX, OriginY
- .DrawCurveLineTo OriginX + GraphRangeX, OriginY
- .EndDrawCurve
- .SetOutlineColor 5, 0, 0, 0, 0 ' Black
-
- ' open data file for input
- ON ERROR GOTO OnOpenError ' trap error : file not found?
- OPEN "chartdat.txt" for input as 1
- ON ERROR EXIT ' No more trapping errors
- INPUT #1, NumBars&, Range&, Cutoff& ' first line in file
- Cutoff = Cutoff/Range * GraphRangeY
-
- For i = 0 To NumBars-1
-
- INPUT #1, Height& ' indicates height (0-100)
- Height = Height/Range * GraphRangeY
- Leftx = OriginX + i * (Width + Gap) + Gap
- Top = Height + OriginY
-
- ' draw the shadow first : use offset
- .CreateRectangle Top - Offset, Leftx + Offset, Top-Height, Leftx+Width + Offset, 0
- .ApplyUniformFillcolor 5, 100, 100, 100, 0
-
- ' draw the foreground : use different colors
- .CreateRectangle Top, Leftx, Top-Height, Leftx+Width, 0
- IF Height > Cutoff THEN
- .ApplyUniformFillcolor 5, 255, 0, 255, 0
- ELSE
- .ApplyUniformFillcolor 5, 175, 0, 255, 0
- END IF
-
- Next i
-
- ' draw cut off line
- .BeginDrawCurve OriginX, Cutoff + OriginY
- .DrawCurveLineTo OriginX + GraphRangeX, Cutoff + OriginY
- .EndDrawCurve
- .ApplyOutline 254, 4, 0, 0, 100, 0, 9, 0, 0, 0
- .SetOutlineColor 5, 100, 100, 100, 0
- .OrderToBack
-
- close #1
- STOP ' so that we don't execute the error handler!!
-
- OnOpenError :
- ' the file did not exist, so create one
- IF ERRNUM = 201 THEN
- ErrMsg$ = "Data File chartdat.txt does not exist" + chr(13)
- ErrMsg$ = ErrMsg$ + "Do you want one to be created?"
- ret% = MESSAGEBOX (ErrMsg$,"Error Handling", 4+32)
- IF ret% = 7 THEN STOP
- OPEN "chartdat.txt" FOR OUTPUT AS 2
- RANDOMIZE
- PRINT #2, "10, 200, 100"
- FOR i = 1 to 10
- PRINT #2, RND(200)
- NEXT i
- CLOSE #2
- RESUME
- END IF
-
- END WITHOBJECT
-
-