Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts.

Similar presentations


Presentation on theme: "Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts."— Presentation transcript:

1 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 1 Chapter 11: Using Visual Basic to Create Graphics

2 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 2 Types of Graphics Graphics are very useful for handling data or information visually. Engineers use graphics to design machines and structures using CAD (computer-aided design) graphics. Artists use graphics to create images for both business and artistic purposes. We have already used clipart graphics created by others in some of our projects. A graphical representation of business data is referred to as analysis or business graphics.

3 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 3 Types of Business Graphics Business graphics include such types as line, bar, and pie charts. Line charts are often used to show trends over time. The incline or decline of each line segment demonstrates the change in values on the vertical axis for each unit change on the horizontal axis. Bar charts can be used to compare quantities using vertical or horizontal bars, where the length or height of the bar represents each quantity. Pie charts can be used to compare parts of some quantity (budget, income, and so on) using a circular diagram. Scatter diagrams can be used to look for patterns in data.

4 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 4 Creating Business Graphics with VB To plot mathematical equations or create business graphics, follow a six-step approach: –Decide on a type of control to use in creating the graphic. –Set up the coordinate system for the control. –Add horizontal and vertical axes to the control. –Add division marks and labels to the axes. –Draw the graphic on the control. –Add titles and legends to the graphic.

5 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 5 Methods for Drawing Axes The picture box is one of a variety of controls that can be used for drawing graphics. The coordinate axis is set using the Scale method or the ScaleTop, ScaleLeft, ScaleHeight, and ScaleWidth properties. Straight lines can be drawn using the Line method, in which the beginning and ending values of the line are specified. The Line method is often used to draw axes for a graph. The AutoRedraw property must be used in the Form_Load event procedure to display the axes.

6 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 6 The Scale Method Scale(HUL, VUL) - (HLR, VLR) where HUL = horizontal measure of the upper left- hand corner VUL = vertical measure of the upper left- hand corner HLR = horizontal measure of the lower right- hand corner VLR = vertical measure of the lower right- hand corner

7 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 7 The Line Method Object.line (HUL, VUL) - (HLR, VLR) where HUL = horizontal measure of the upper left- hand corner VUL = vertical measure of the upper left-hand corner HLR = horizontal measure of the lower right- hand corner VLR = vertical measure of the lower right-hand corner

8 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 8 Properties for Axes and Labels The CurrentX and CurrentY properties are used to determine the location of division marks and labels on the graph. The division marks are added to the axes with the Line control. The labels are added to the division marks with the Print method. The TextHeight and TextWidth properties are used to position the labels. The actual graph is plotted using the PSet method within a For-Next Loop. The increments in the loop must be kept small to avoid gaps in the graph.

9 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 9 Adding Division Marks and Labels Determine the width of the label with the TextWidth property. Divide the label width by two and subtract the result from the current location to determine the value of CurrentX where the label should be added. Set the CurrentY for the label to the value at the bottom of the division marks. Add the label to the graph or chart with the picture box Print method.

10 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 10 Charts for Vintage Videos Five different charts are going to be created for Vintage Videos: –a line chart for total rentals –line charts for the three types of rentals –a bar chart for total rentals –bar charts for the three types of rentals –a pie chart for distribution of total rentals

11 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 11 Steps for Creating Vintage Videos Charts The first step in creating a chart is to design the chart showing the axes and labels. The second step is to set the coordinate axes. This often involves using different scales for the vertical and horizontal axes and placing the origin off-center. The third step is to add the division marks and labels on the vertical and horizontal axes.

12 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 12 Creating Line Charts Line charts are drawn using the Line method to connect the points on the chart. Titles are added to a line chart in a manner similar to that used to add labels. We can draw multiple lines on a chart by using the DrawStyle property to distinguish between the various lines. For multiple-line charts, a legend is also needed to show the purpose of each line.

13 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 13 DrawStyle Property Constants and Values Line StyleVB ConstantValue SolidvbSolid0 DashvbDash1 DotvbDot2 Dash DotvbDashDot3 Dash Dot DotvbDashDotDot4 TransparentvbTransparent5

14 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 14 Creating Bar Charts Bar charts are drawn using the B (box) option with the Line method. The parameters for the Line method give the coordinates of the corners of the box. Multiple bars can be distinguished using the FillStyle property. A legend is added for multiple bars in much the same way as for multiple lines.

15 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 15 FillStyle Property Options Fill StyleVB ConstantValue SolidvbFSSolid0 TransparentvbFSTransparent1 Horizontal LinesvbHorizontalLine2 Vertical LinesvbVerticalLine3 Upward DiagonalvbUpwardDiagonal4 Downward DiagonalvbDownwardDiagonal5

16 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 16 Creating Pie Charts Pie charts are drawn using the Circle method, where the center of the circle and the radius determine the location and size of the circle. To draw the segments of the pie chart, we add parameters to the Circle method that will draw sectors rather than complete circles. These sectors are measured in radians. For the center of the circle to be connected to the sectors, the sector parameters must be negative. In a manner similar to that used for bar charts, the sectors can be filled using the FillStyle property and a legend can be added.

17 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 17 The Circle Method object.Circle (x, y), radius, color, start, end where –x, y = the center of the circle –radius = the radius of the circle –color = the color for the circle –start = the starting point in radians for any sector of the circle –end = the ending point in radians for any sector of the circle

18 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 18 Three Steps to Create Pie Chart for Vintage Videos Compute cumulative fractions for each of three types of videos. Set the coordinate system for the form. Draw pie chart using Circle method.

19 Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts Circle Method Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy 19 Creating Scatter Diagrams Scatter diagrams help the user look for patterns in data. A scatter diagram can be drawn in Visual Basic by using the FillStyle property and the Circle method to draw circles. The circles are plotted for pairs of values, with the radius of each circle being set to a small fraction of the horizontal axis scale.


Download ppt "Copyright © 2001 by Wiley. All rights reserved. Chapter 11: Using Visual Basic to Create Graphics Scale Method Line Method Line Charts Bar Charts Pie Charts."

Similar presentations


Ads by Google