
488 CHAPTER 8 Single-Dimensional Arrays
8.3.8 Displaying Array Data as a Bar Chart
One way to display array data is graphically, by drawing a bar chart. For
example, the bar chart in Figure 8.15 displays the data in the cellBills array.
Each bar is simply a rectangle. Example 8.9 shows the code to generate
Figure 8.15.
1 /* BarChart Applet
2 Anderson, Franceschi
3 */
4
5 import javax.swing.JApplet;
6 import java.awt.Graphics;
7 import java.awt.Color;
8
9 public class BarChartApplet extends JApplet
10 {
11 final int LEFT_MARGIN = 20; // starting x coordinate
12 final int BASE_Y_BAR = 150; // bottom of the bars
13 final int BASE_Y_VALUE = 175; // bottom of the ...