Sales Bar Chart

This file is part of Timex Sinclair Public Domain Library Tape 1001 . Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Business

This program generates a dual-series horizontal bar chart displaying five years of simulated sales figures for two product lines, nuts and bolts. It uses a 5×2 array to store randomly generated sales values (integers in the range 10–20) and renders the chart using block graphics characters to distinguish where both series overlap, where only nuts exceed a threshold, and where only bolts do. The x-axis labels are printed manually across two lines to represent values 0 through 20 in steps of 2. Output uses tab-separated formatting with inverse-video characters in column headers and a manually positioned axis scale.


Program Analysis

Program Structure

The program is divided into four logical phases, separated by line-number ranges:

  1. Lines 5–10: Title REM and array declaration.
  2. Lines 100–140: Data initialisation — fills the 5×2 array S with random values.
  3. Lines 200–499: Output — prints the chart header, iterates over years, draws bars, and prints the x-axis scale.
  4. Lines 500–510: Save/auto-run block, not part of normal execution.

Data Generation

The two-dimensional array S(5,2) stores values for five years and two product lines (nuts = column 1, bolts = column 2). Each value is generated by INT(RND*11+10), producing integers uniformly distributed in the range 10–20 inclusive. This means every bar will be at least half the maximum chart width, giving a reasonably compact but always-populated chart.

Bar Rendering Technique

For each year, a loop over K from 1 to 20 tests the relationship between the two series values and the current column position, printing one of three block graphic characters per cell:

ConditionEscapeGlyphMeaning
S(J,1)>=K AND S(J,2)>=K\!!Both nuts and bolts reach this column
S(J,1)>=K AND S(J,2)<K\..Only nuts reach this column
S(J,2)>=K AND S(J,1)<K\~~Not a standard zmakebas escapeOnly bolts reach this column

The three IF statements at lines 320–340 are mutually exclusive by construction (the cases cover all possibilities when K is within the range of either value), so no ELSE or branching is needed. When neither series reaches column K, none of the conditions is true and nothing is printed, which naturally terminates the bar.

Notable Idioms

  • The header at line 200 uses inverse-video characters embedded in string literals (e.g. %V, %E, etc.) to highlight the column headers “FIVE YEAR SALES FIG.” and “FOR NUTS() AND BOLTS()”.
  • Year labels are computed on the fly as 1984+J (line 305), covering 1985–1989, avoiding a separate lookup array.
  • Double PRINT statements at lines 360–370 insert blank lines between year rows, giving the chart visual breathing room without cursor manipulation.
  • The x-axis scale (lines 400–410) is split across two PRINT statements to handle the two-digit label “10” through “20” breaking into a staggered layout — a common manual workaround for fixed-width character grids.

Anomalies and Observations

  • The bar loop runs to K=20 (line 310), matching the maximum possible value from data generation, so no bar can overflow. However, if a value were exactly 20, the rightmost cell would still be printed correctly.
  • The x-axis label at line 400 shows values “0 2 4 6 8 1 1 1 1 1 2” and line 410 continues “0 2 4 6 8 0”, together representing 0, 2, 4, 6, 8, 10, 12, 14, 16, 18, 20. Each bar cell is one character wide, so the scale is in units of 1, not 2 — the printed axis labels do not correctly correspond to the bar positions and are purely decorative approximations.
  • The PRINT "YEAR",, at line 250 uses double comma tab-stops to position the heading, but since bars begin immediately after the year number with a space (line 305), the visual alignment of “YEAR” with the bars may be off by the width of the year field.
  • The STOP at line 499 prevents execution from falling through to the SAVE/RUN block, which is a standard technique for embedding auto-save metadata in a program listing without it executing during normal runs.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10001 – 10050.

Related Products

Related Articles

Related Content

Image Gallery

Sales Bar Chart

Source Code

   5 REM %S%A%L%E%S% %C%H%A%R%T
  10 DIM S(5,2)
 100 FOR J=1 TO 5
 110 FOR K=1 TO 2
 120 LET S(J,K)=INT (RND*11+10)
 130 NEXT K
 140 NEXT J
 200 PRINT "FI%VE YEAR SALES FIG.","FOR NUTS()AND BOLTS()",,,
 250 PRINT "YEAR",,
 300 FOR J=1 TO 5
 305 PRINT 1984+J;" ";
 310 FOR K=1 TO 20
 320 IF S(J,1)>=K AND S(J,2)>=K THEN PRINT "\!!";
 330 IF S(J,1)>=K AND S(J,2)<K THEN PRINT "\..";
 340 IF S(J,2)>=K AND S(J,1)<K THEN PRINT "\~~";
 350 NEXT K
 360 PRINT 
 370 PRINT 
 380 NEXT J
 400 PRINT "    0 2 4 6 8 1 1 1 1 1 2"
 410 PRINT "              0 2 4 6 8 0"
 499 STOP 
 500 SAVE "1003%9"
 510 RUN 

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

People

No people associated with this content.

Scroll to Top