Setting Up Bar Charts

Author(s): Jon Passler; James Grosjean
Publication: SYNC
Date: Special Issue 1982
Pages: 28

8K ROM / 1K RAM

 10 DIM B(20)
20 FOR I=1 TO 20
30 PRINT I;" ";
40 INPUT B(I)
50 PRINT B(I)
60 IF NOT B(I) THEN STOP
100 NEXT I

Subroutine

110 FOR I=15 TO 0 STEP -1
120 PRINT AT ABS I-15,I<10;I;"-
";
130 FOR J=1 TO 20
140 IF NOT B(J) THEN GOTO 200
150 LET D=B(J)+-I*100
160 IF D<-25 THEN PRINT " ";
170 IF D>-26 AND D<25 THEN PRIN
T "▄";
180 IF D>24 THEN PRINT "▌";
190 NEXT J
200 PRINT
210 NEXT I
320 REM B(17)

Bar Chart Program

A bar chart is one of the most commonly used methods of graphically presenting data for quick interpretation. Such charts work nicely within the constraints of the Sinclair computers. Beside making for a good display, they provide an excellent way of storing data.

The program listed here works with 1K to chart two years of monthly checking account balances with vertical bars. The graph is set up for a range of $0 to $1500, but can be modified for other ranges with a few changes and some trial-and-error experimentation. Of course, any other sort of data such as monthly rainfall or average temperatures, miles-per-gallon, electricity use, or frequency distributions (histograms) can be plotted.

Because of memory limitations the array storing the data is created and filled in a routine that is later erased (lines 10-100). All elements of the array contain either data or zeroes, and line 320 is used to show the user which element of the array should be filled next. To add a monthly figure enter 330 LET B(17)=XXXX, then GO TO 330 and N/L, and finally erase line 330 and update line 320 to REM B(18).

After entering the program, you can enter the following data to see how it works: 1012, 796, 931, 1236, 1252, 1088, 786, 1132, 1194, 908, 1113, 896, 913, 849, 553, 429.

If you have more memory than 1K and want to enter more data, the following changes can be experimented with.

Subroutine:

  • 10: Increase B
  • 20: Change the 20 to the new figure for B.
  • 25: SCROLL

Bar Chart Program:

  • 130: Change the 20 to the new figure for B.

Notes:

  • 170: graphic on 3
  • 180: graphic on 8

Adapted for ZX81 by James Grosjean.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.