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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

280 <strong>Computer</strong> <strong>Programming</strong> <strong>Concepts</strong> <strong>and</strong> <strong>Visual</strong> <strong>Basic</strong><br />

The FillStyle <strong>and</strong> FillColor properties can be used when creating rectangles. The statements<br />

picBox.FillStyle = s=<br />

picBox.Fill Color = vbColor<br />

pic Box.Line (x1, y1) - (x2, y2), , 8<br />

draw a rectangle filled with the pattern specified by s in the color specified by vbColor. This<br />

capability is often used when creating the legend to accompany a graph.<br />

The procedure for drawing a pie chart is as follows:<br />

1. Read the categories <strong>and</strong> the quantities into arrays, such as category() <strong>and</strong><br />

quantity().<br />

2. Determine the radius lines. The number associated with the ith radius line is<br />

cumPercent(i). This number is a total of quantity(i) <strong>and</strong> the preceding<br />

percentages.<br />

3. Draw <strong>and</strong> fill each sector with a pattern. The first sector extends from the horizontal<br />

radius line to radius line 1, the second sector from radius line 1 to radius<br />

line 2, <strong>and</strong> so on.<br />

4. Draw rectangular legends to associate each sector with its category.<br />

EXAMPLE 5<br />

Table 9.2 gives the market share of Internet browsers for July 1998. Construct a pie chart that displays the<br />

market share.<br />

TABLE 9.2<br />

Browser Market Share, July 1998<br />

Percent of Total Market<br />

Internet Explorer 44<br />

Netscape Navigator 42<br />

Other 14<br />

SOLUTION:<br />

Figure 9-23 shows the output displayed by the following program.<br />

Private Sub cmdDraw_Click()<br />

Dim numItems As Integer, radius As Single<br />

‘Draw pie chart of Browser Market Share<br />

numItems = 3<br />

ReDim category(1 To numItems) As String<br />

ReDim quantity(1 To numItems) As Single<br />

Call ReadData(category(), quantity(), numItems)<br />

Call DrawData(quantity(), numItems, radius)<br />

Call ShowLegend(category(), numItems, radius)<br />

Call ShowTitle(radius)<br />

End Sub<br />

Private Sub DrawData(quantity() As Single, numItems As Integer, _ radius As<br />

Single)<br />

Dim circumf As Single, leftEdge As Single, rightEdge As Single<br />

Dim topEdge As Single, bottomEdge As Single, i As Integer<br />

Dim startAngle As Single, stopAngle As Single<br />

‘Draw <strong>and</strong> fill each sector of pie chart<br />

‘All scaling <strong>and</strong> text positioning done as a percentage of radius radius = 1<br />

‘actual value used is not important<br />

‘Make picture 4 radii wide to provide plenty of space for<br />

‘circle <strong>and</strong> legends. Place origin 1.25 radii from left edge;

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

Saved successfully!

Ooh no, something went wrong!