Vb Chapter 10
Transcript of Vb Chapter 10
-
8/13/2019 Vb Chapter 10
1/2
1
10.The Graphical Display of Data10.1.INTRODUCTION TO GRAPHS
Specifying a Coordinate System
picBox.Scale (a,d) - (b,c) : specifies x-axis range from a to b, and y-axis range from c to d.
The ordered pair (a,d) gives the coordinates of the top left corner of the picture box.
The ordered pair (b,c) gives the coordinates of the lower right corner of the picture box.
Graphics Methods for Drawing Lines, Points, and Circles
picBox.Line (x1,y1) - (x2,y2) : draws line segment from (x1,y1) to (x2,y2) in picture box.
picBox.PSet(x,y) : plots the point (x,y).
picBox.Circle(x,y),r : draws the circle with center (x,y) and radius r(in x axis units).
Positioning Text
A picture box has two properties (CurrentX, CurrentY) and two methods
(TextHeight,TextWidth) that allow us to precisely position text alongside graphics.
CurrentXand CurrentYrecord the precise horizontal and vertical location at which the next
character will be printed.
CurrentYis the location for the top of the character cursor.
Obtaining a good range of values for a graph with only positive values
picOutput.Scale (-0.2 * r, 1.2 * h) - (1.2 *r, -0.2 * h)
where r = x coordinate of the rightmost point to be drawn, h = y coordinate of the highest point to be
drawn.
Line clipping
If one or more points in a graphics method fall outside the picture box part of the line is clipped.
More than one Scale statements
A program can execute a picOutput.Scale statement more than once.
The new statements have no effect on text and graphs already drawn; however, future graphics
statements will use the new coordinate system.
-
8/13/2019 Vb Chapter 10
2/2
2
Producing colorful displays
To draw lines, points, and circles in color place a vbColorconstant at the end of the corresponding
command.
Example:picBox.Line (x1,y1) - (x2,y2), vbRed
10.2.LINE CHARTS
Line charts (x-y plots) represent y = f(x) as lines and data points.
Use labels for the axes and plot. Describe legend to identify more than one curve if needed.
See examples in section 10.2 of the textbook.
Line Styling
Use the statementpicBox.DrawStyle = s
to select different line styles
s = 0 ______________________ s = 3 - -- - -- - -- - -- - -- - -- - --
s = 1 _ _ _ _ _ _ _ _ _ _ _ s = 4 - - --- - - --- - - --- - - --- - -
s = 2 - - - - - - - - - - - - - -
10.3. BAR CHARTS
Bar charts (e.g., histograms, etc.) are produced by drawing rectangles using a variation of the line
statement.
picBox.Line (x1,y1) - (x2,y2), , B: produces a blank rectangle.
picBox.Line (x1,y1) - (x2,y2), , BF: produces a filled rectangle.
10.4. PIE CHARTS
Pie charts are produced by drawing circular sectors using the Circle and Line statements.
Let c = 2be the circumference of a unit circle, and let 0< a < b < 1, then the statement
picBox.Circle (x,y), r, , a * c, b * c
plots the circular arc limited by the angles a*c = 2a, and b*c = 2b.
Also, the statement
picBox.Circle (x,y), r, , - a * c, - b * c
plots the circular sector limited by the angles a*c = 2a, and b*c = 2b. Note: when a = 0, then the
radius corresponding to that point is not plotted. To avoid this problem use a = 0.000001, rather than a = 0.
Use the FillStyle property to fill the circular sector. See Figure 10.28 for different styles.
Use the statement picBox.FillColor = vbColor(a vbColor constant) for colorful sectors.