PICTURE HISTOGRAM (SINGLE VALUES(), STRING LABELS(), BYTE ITEM_COUNT) !+ ! This sample BASIC program draws a histogram using the values in the array ! VALUES. These values must be SINGLE values in the range 0 to 8. Values ! outside of this range will be set to zero. Each bar is labeled with the ! corresponding string in the array LABELS. Each label can be a maximum of ! 6 characters long. Longer strings will be truncated. ITEM_COUNT ! is the number of bars to plot. The maximum number of bars that will fit ! on a screen is 8. !- DECLARE SINGLE CURRENT_VALUE, X, Y, & STRING CURRENT_LABEL !+ ! Verify the input !- IF ITEM_COUNT > 8 THEN PRINT "There is only room for eight items." ITEM_COUNT = 8 END IF FOR I = 0 TO ITEM_COUNT-1 IF VALUES (I) < 0 OR VALUES (I) > 8 THEN PRINT "Value must be in the range 0 to 8. Illegal value set to zero." VALUES (I) = 0 END IF IF LEN (LABELS(I)) > 6 THEN PRINT "Label must be six characters or less. String truncated." LABELS(I) = LEFT$ (LABELS(I), 6) END IF NEXT I !+ ! Draw the grid. !- CLEAR PLOT LINES: 0.1,0.95; 0.1,0.1; 0.95,0.1 !+ ! Mark off the scale on the vertical axis with an "_" character. !- Y = 0.2 FOR I = 2 TO 9 GRAPH TEXT AT 0.1, Y : "_" Y = Y + 0.1 NEXT I !+ ! Label the vertical axis with a scale from 0 through 8. ! Use the CHAR font of the default text size. !- SET TEXT FONT 1, "CHAR" DATA 0,1,2,3,4,5,6,7,8 Y = 0.1 FOR I = 0 TO 8 READ CURRENT_LABEL GRAPH TEXT AT 0.05, Y : CURRENT_LABEL Y = Y + 0.1 NEXT I !+ ! Draw the bars and label them. Change to STROKE precision and ! make the text smaller, so that longer labels will fit. Center ! each label under its bar. !- SET AREA COLOR 3 SET TEXT COLOR 2 SET TEXT FONT 1, "STROKE" SET TEXT JUSTIFY "CENTER", "BASE" ASK TEXT HEIGHT H SET TEXT HEIGHT H * 0.8 ASK TEXT EXPAND EX SET TEXT EXPAND EX * 0.8 X = 0.2 DELTA = 0.02 FOR J = 0 TO ITEM_COUNT-1 CURRENT_VALUE = (VALUES (J) + 1) / 10.0 ! Scale the value PLOT AREA : X-DELTA, 0.1; X-DELTA, CURRENT_VALUE; & X+DELTA, CURRENT_VALUE; X+DELTA, 0.1 GRAPH TEXT AT X, 0.05 : LABELS(J) X = X + 0.1 NEXT J END PICTURE