Bar Chart

Author(s): Jon Passler
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v3 n1 (Volume 3, Issue 1)
Date: January 1982
Pages: 15

Bar Chart uses the 8K PLOT function to simplify the bar chart algorithm. It assumes B(15) has been filled, or partially filled, with values between 0 and 2000.

Lines 20-50 provide scale marks and label 3 of them in 1000s. Line 60 should be 1 TO (size you dimension B to). Line 80 will STOP at the first unfilled element of B. All elements are initially set to 0 with the new ROM. Line 90 sets the range–100 per pixel in this case–and makes the half-range adjustment (-50) so each pixel represents a midpoint (eg. pixel 100 represents values from 50-149). Line 100 spaces between each bar (A*2) and tabs over to allow for the scale (+3). Line 130 means that to enter a new value, simply enter LET B(A)=(new value), press NL, then GOTO 1. Do not type RUN again.

Set line 90 for the desired pixel range, adjust line 100 to make more room for your scale, if needed, and experiment with various scale representations. I kept mine simple to save memory. DIM(B) can be larger or smaller than 15.

   1 DIM B(15)
2 FOR X=1 TO 15
3 INPUT B(X)
4 NEXT X
10 REM BAR CHART (0-2000)
20 FOR A=11 TO 21
30 PRINT AT A,1;"-"
40 NEXT A
50 PRINT AT 11,0;"2";AT 16,0;"1";AT 21,0;"0"
60 FOR A=1 TO 15
70 FOR P=1 TO 43
80 IF B(A)=0 THEN STOP
90 IF B(A)<P*100-50 THEN GOTO 120
100 PLOT A*2+3,P
110 NEXT P
120 NEXT A
130 REM INPUT B(A)
Syntactic Sum: 19586, 8K