19.12.2012 Views

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

Computer Programming Concepts and Visual Basic David I. Schneider

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

9.2 LINE CHARTS<br />

A line chart displays the change in a certain quantity in relation to another quantity (often<br />

time). The following steps produce a line chart.<br />

1. Look over the data to be displayed. A typical line chart displays between 3 <strong>and</strong><br />

20 items of data corresponding to evenly spaced units of time: years, months,<br />

or days. The positions on the x axis will contain labels such as “Jan Feb Mar<br />

Apr . . .” or “1996 1997 1998 1999 . . .”. These labels can be placed at the<br />

locations 1, 2, 3, . . . on the x axis.<br />

2. Choose a coordinate system based on the number of data items <strong>and</strong> the size of<br />

the quantities. A convenient scale for the x axis is from –1 to one more than the<br />

number of data items. The scale for the y axis is determined by the largest quantity<br />

to be displayed.<br />

3. Draw the line segments. It is a good idea to draw a small circle around the end<br />

points of the line segments.<br />

4. Draw <strong>and</strong> label tick marks on the coordinate axes. The x axis should have a tick<br />

mark for each time period. The y axis should have at least one tick mark to indicate<br />

the magnitude of the quantities displayed.<br />

5. Title the chart, <strong>and</strong> give the source of the data.<br />

EXAMPLE 1<br />

Table 9.1 gives enrollment data for 2-year colleges taken from the Statistical Abstract of the United States<br />

(the data for 2000 is a projection). Write a program to display the total enrollments for the given years in<br />

a line chart.<br />

TABLE 9.1<br />

Two-Year College Enrollments (in Thous<strong>and</strong>s)<br />

Year 1960 1970 1980 1990 2000<br />

Male 283 1375 2047 2233 2398<br />

Female 170 945 2479 3007 3358<br />

Total 453 2320 4526 5240 5756<br />

SOLUTION:<br />

Figure 9-9 shows the graph that results from executing the following program. The data in ENROLL.TXT<br />

are taken from the first <strong>and</strong> fourth lines of Table 9.1. For example, the first line in the file is “1960”, 453.<br />

(Explanatory remarks follow the program.)<br />

‘In (Declarations) section of (General)<br />

Dim numYears As Integer, maxEnroll As Single<br />

Private Sub cmdDraw_Click()<br />

‘Line Chart of Total Two-Year College Enrollments<br />

numYears = 5<br />

ReDim label(1 To numYears) As String<br />

ReDim total(1 To numYears) As Single<br />

Call ReadData(label(), total())<br />

Call DrawAxes<br />

Call DrawData(total())<br />

Call ShowTitle<br />

Call ShowLabels(label())<br />

End Sub<br />

Private Sub DrawAxes()<br />

‘Draw axes<br />

Line Charts 267

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!