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.

9.4 PIE CHARTS<br />

Drawing pie charts requires the Circle method <strong>and</strong> the FillStyle property. The Circle method<br />

draws not only circles, but also sectors (formed by an arc <strong>and</strong> two radius lines). The FillStyle<br />

property determines what pattern, if any, is used to fill a sector. The FillColor property can be<br />

used, if desired, to lend color to the fill patterns.<br />

Figure 9-16 shows a circle with several radius lines drawn. The radius line extending to<br />

the right from the center of the circle is called the horizontal radius line. Every other radius<br />

line is assigned a number between 0 <strong>and</strong> 1 according to the percentage of the circle that must<br />

be swept out in the counterclockwise direction in order to reach that radius line. For instance,<br />

beginning at the horizontal radius line <strong>and</strong> rotating 1/4 of the way around the circle counterclockwise,<br />

we reach the radius line labeled .25.<br />

FIGURE 9-16 Numbers Assigned to Radius Lines<br />

EXAMPLE 1<br />

In Figure 9-17, what percentage of the area of the circle lies in the shaded sector?<br />

FIGURE 9-17 Circle for Example 1<br />

SOLUTION:<br />

The percentage of the circle contained between the radius lines labeled .15 <strong>and</strong> .35 is 35% – 15%, or 20%.<br />

The statement<br />

picBox.Circle (x, y), r<br />

draws the circle with center (x, y) <strong>and</strong> radius r. More precisely, the length of the horizontal radius<br />

line will be r units in the scale for the x axis determined by the picBox.Scale statement.<br />

If 0 < a < b < 1 <strong>and</strong> c is the circumference of the unit circle (2*π), then the statement<br />

picBox.Circle (x, y), r, , a * c, b * c<br />

draws an arc from the end of radius line a to the end of radius line b. See Figure 9-18(a). The<br />

statement<br />

picBox.Circle (x, y), r, , -a * c, -b * c<br />

draws the sector corresponding to that arc. See Figure 9-18(b).<br />

Pie Charts 277

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

Saved successfully!

Ooh no, something went wrong!