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.

‘space of 1.75 radii will remain on right for legends.<br />

leftEdge = -1.25 * radius<br />

rightEdge = 2.75 * radius<br />

‘Force vertical scale to match horizontal scale; ‘center origin vertically<br />

topEdge = 2 * radius * (picShare.Height / picShare.Width)<br />

bottomEdge = -topEdge<br />

picShare.Cls<br />

picShare.Scale (leftEdge, topEdge)-(rightEdge, bottomEdge)<br />

circumf = 2 * 3.14159<br />

ReDim cumPercent(0 To numItems) As Single<br />

cumPercent(0) = .0000001 ‘a value of “zero” that can be made negative<br />

For i = 1<br />

To numItems cumPercent(i) = cumPercent(i - 1) + quantity(i)<br />

startAngle = cumPercent(i - 1) * circumf<br />

stopAngle = cumPercent(i) * circumf<br />

picShare.FillStyle = (8 - i) ‘use fill patterns 7, 6, <strong>and</strong> 5<br />

picShare.Circle (0, 0), radius, , -startAngle, -stopAngle<br />

Next i<br />

End Sub<br />

Private Sub Locate (x As Single, y As Single)<br />

picShare.CurrentX = x<br />

picShare.CurrentY = y<br />

End Sub<br />

Private Sub ReadData(category() As String, quantity() As Single, _ numItems As<br />

Integer)<br />

Dim i As Integer ‘Load categories <strong>and</strong> percentages of market share<br />

‘Assume the data have been placed in the file BROWSERS.TXT<br />

‘(First line in file is “Internet Explorer”, .44)<br />

Open “BROWSERS.TXT” For Input As #1<br />

For i = 1 To numItems<br />

Input #1, category(i), quantity(i)<br />

Next i<br />

Close #1<br />

End Sub<br />

Private Sub ShowLegend(category() As String, numItems As Integer, _ radius As<br />

Single)<br />

Dim lblHght As Single, legendSize As Single<br />

Dim i As Integer, vertPos As Single<br />

‘Place legend centered to right of pie chart<br />

‘Make separation between items equal to one line of text<br />

‘“Text lines” needed for legends is thus (2*numItems-1)<br />

lblHght = picShare.TextHeight(“ ”)<br />

legendSize = lblHght * (2 * numItems - 1)<br />

For i = 1 To numItems<br />

picShare.FillStyle = (8 - i)<br />

vertPos = (legendSize / 2) - (3 - i) * (2 * lblHght)<br />

picShare.Line (1.1 * radius, vertPos)-(1.4 * radius, _ vertPos +<br />

lblHght), ,B<br />

Call Locate(1.5 * radius, vertPos)<br />

picShare.Print category(i)<br />

Next i<br />

End Sub<br />

Pie Charts 281

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

Saved successfully!

Ooh no, something went wrong!