Pie Chart: A Refinement

Author(s): John Pazmino
Publication: Syntax
Pub Details: Syntax/Syntax ZX80 v4 n11 (Volume 4, Issue 11)
Date: November 1983
Pages: 22

Refining Ron Oblander‘s chart (Nov.82) makes it run faster and puts table and chart on 1 display. But, it omits the segment titles.

After entering PC, SAVE using GOTO 970. It comes up running and stops with a 9 report. For another chart, RUN again.

After a title screen, PC asks the number of segments. You enter up to 18, the most the table holds on one screen. Then enter segment values one by one. After the last value, the computer shifts to FAST for about 6 seconds to produce the pie outline and table heading. Now in SLOW, the computer lays in the segments and table. At the end you can COPY the screen to a printer.

On the chart, segment 1 starts at the 12 o’clock position; others follow serially clockwise. The table gives segment number, value, percent of pie, & total of values.

Variables Q and R control pie position and radius. PC puts the pie in the lower right corner with an 18-pixel radius. The trig work exploits ZX/TS’s internal MOD feature. One array, E(C), holds each segment value. I serves as index variable in two loops. You can use tokens in the print statements (Syntactic Sum here is for words spelled out.–AZ). Variable N0 carries the number 0.

   1 LET N0=0
2 PRINT AT 10,N0;"PIECHART FOR UP TO 18 SEGMENTS"
3 PAUSE 200
4 CLS
6 LET T=N0
8 LET R=18
10 LET Q=45
12 LET W=N0
15 PRINT " INPUT NUM OF SEG:"
20 INPUT C
22 DIM E(C)
26 FOR I=1 TO C
41 PRINT " THEN INPUT VAL FOR SEG ";I;":"
42 INPUT E(I)
45 CLS
57 LET T=T+E(I)
59 NEXT I
100 FAST
105 PLOT Q,R
120 FOR P=N0 TO 6.3 STEP 0.056
140 PLOT Q+SIN P*R,R+COS P*R
200 NEXT P
205 PRINT AT N0,N0;"SEG";TAB 4;"VAL ";TAB 10;"O/O"
217 SLOW
220 FOR I=1 TO C
230 LET Z=E(I)*2*PI/T
405 LET W=Z+W
410 LET M=SIN W
420 LET N=COS W
560 FOR J=N0 TO R
570 PLOT Q+M*J,R+N*J
580 NEXT J
920 PRINT AT I,N0;I;TAB 4;E(I);TAB 10;INT (E(I)*100/T+0.5)
930 NEXT I
960 PRINT TAB 4;"----";TAB N0;"SUM ";T
965 STOP
970 SAVE "PIECHART"
980 RUN
SYNTACTIC SUM: 38512, 8K ROM

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