Rocni bilance – Grafik (Annual Bar Chart)

Type
Utility
Category
Business graphics / 3-D bar chart
Published in
Atari Magazin (Germany); Czech/Slovak version on the disk magazine Flop, issue 8
Language
Atari BASIC
Requirements
Any 8-bit Atari with Atari BASIC; 16K or more (GRAPHICS 8)

About the program

Home-finance charting was a favourite magazine type-in, and this is a tidy example. You enter a year and a value for each month, and the program draws twelve solid-looking 3-D columns on a hi-res screen, scaled so that the best month reaches the top of the axis. It comes from the German Atari Magazin and was reissued on the Czech disk magazine Flop 8, and the listing shows both parents. The variable names and REMs are German: MONAT is month, WERT value, BALKEN HOEHE bar height, BALKEN PLOTTEN plot the bars, and the axis labels spell out Jan, Feb, Mar… Mai, Okt, Dez. The prompts and the month names in the DATA, on the other hand, are Czech/Slovak: ROCNI BILANCE means "annual balance", ROK "year", and MAREC, MAJ, JUN and JUL are the local spellings of the months.

Typing it in

  • {CLEAR} is ESC then SHIFT-CLEAR, {UP} is ESC then CTRL-minus, and {DOWN} is ESC then CTRL-equals.
  • {inverse}…{/inverse}: type the enclosed text with the inverse-video key on. Lines 4010–4030 are the month labels, three rows of inverse letters separated by inverse spaces. Read them downwards: J-a-n, F-e-b, M-a-r…
  • Line 3020 shows 1.4000000000000001. That's an artefact of converting the tokenised program on a PC, so type 1.4.
  • Line 5075 (ST=22) is never used in a meaningful way and can be left in or out.

How to use it

  1. At ROK ==> type the year. It's printed under the chart as ROCNI VYROCI followed by the year.
  2. Enter a value for each month (JANUAR ==> …). A negative value restarts the program, and an input error such as typing letters drops you back to the start, thanks to TRAP 100.
  3. The chart appears. Press SPACE to start again.

How it works

Subroutine 2000 finds the largest monthly value (HPROC, the "100 per cent" mark). Subroutine 3000 turns every month into a bar height of up to 140 pixels (1.4 × percentage). The drawing loop at 5000 builds each bar from the bottom up, one scan line at a time: a horizontal line, then a short diagonal for the side face, with one pixel erased at the corner so the front edge stays visible. Line 5030 finishes with the top face. The axis in lines 4050–4060 has long ticks every 14 pixels (10 per cent) and short ticks every 7. The light background with dark ink comes from SETCOLOR 2,15,15 and SETCOLOR 1,0,0.

Variations to try

  • Label the bars with their values. GRAPHICS 8 has a text window, so PRINT each value there or POSITION them over the bars.
  • Make it handle negative months by drawing downwards from a middle baseline.

Listing

5 GRAPHICS 0
10 DIM MONAT(12),M$(20),HBALKEN(12)
100 ? "{CLEAR}":? "{UP}":? " ROCNI BILANCE - GRAFIK {inverse}ATARI MAGAZIN {/inverse} ";:TRAP 100:RESTORE
110 ? "{DOWN}{DOWN}{DOWN}"
115 ? "ROK ==> ";:INPUT ROK
117 ? "{DOWN}{DOWN}"
120 FOR I=1 TO 12
130 READ M$:? M$;" ==> ";:INPUT WERT
135 IF WERT<0 THEN RUN
140 MONAT(I)=WERT
150 NEXT I
160 GOSUB 2000
170 GOSUB 3000
180 GOSUB 4000
2000 REM 100 PROCENT
2010 HPROC=MONAT(1)
2020 FOR I=1 TO 12
2030 IF MONAT(I)>HPROC THEN HPROC=MONAT(I)
2040 NEXT I
2050 RETURN
3000 REM {inverse}*** BALKEN HOEHE ***{/inverse}
3010 FOR I=1 TO 12
3015 IF MONAT(I)=0 THEN HBALKEN(I)=0:GOTO 3030
3020 HBALKEN(I)=1.4000000000000001*(MONAT(I)/(HPROC/100))
3030 NEXT I
3040 RETURN
4000 GRAPHICS 8:SETCOLOR 2,15,15:SETCOLOR 1,0,0:COLOR 1:POKE 752,1
4010 ? "{inverse}J F M A M J J A S O N D{/inverse}"
4020 ? "{inverse}a e a p a u u u e k o e{/inverse}"
4030 ? "{inverse}n b r r i n l g p t v z{/inverse}"
4040 ? " ROCNI VYROCI ";ROK;
4050 PLOT 5,150:DRAWTO 5,150-140
4060 FOR I=150 TO 10 STEP -14:PLOT 5,I:DRAWTO 15,I:NEXT I:FOR I=10 TO 150 STEP 7:PLOT 5,I:DRAWTO 10,I:NEXT I
4070 REM {inverse}*** BALKEN PLOTTEN ***{/inverse}
4075 ST=23.5
4080 FOR I=1 TO 12
4090 IF HBALKEN(I)=0 THEN 5040
5000 FOR T=150 TO 150-HBALKEN(I) STEP -1
5010 PLOT 3+(I*ST),T:DRAWTO 3+(I*ST)+10,T:DRAWTO 3+(I*ST)+15,T-5:COLOR 0:PLOT 3+(I*ST)+10,T:COLOR 1
5020 NEXT T
5030 PLOT 3+(I*ST)+15,T-5:DRAWTO 3+(I*ST)+5,T-5:DRAWTO 3+(I*ST),T
5040 NEXT I
5050 OPEN #1,4,0,"K:"
5060 GET #1,R
5070 IF R=ASC(" ") THEN RUN
5075 ST=22
5080 GOTO 5060
6000 DATA JANUAR, FEBRUAR, MAREC, APRIL, MAJ, JUN, JUL, AUGUST, SEPTEMBER, OKTOBER
6010 DATA NOVEMBER, DECEMBER

Credits