1 / 19

Chapter 11: Using Visual Basic to Create Graphics

Chapter 11: Using Visual Basic to Create 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.

nola-joyner
Download Presentation

Chapter 11: Using Visual Basic to Create Graphics

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chapter 11:Using Visual Basic to Create Graphics Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  2. 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 clipartgraphics created by others in some of our projects. A graphical representation of business data is referred to as analysis or businessgraphics. Types of Graphics Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  3. Business graphics include such types as line, bar, and pie charts. Linecharts 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. Types of Business Graphics Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  4. 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. Creating Business Graphics with VB Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  5. 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. Methods for Drawing Axes Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  6. 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 The Scale Method Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  7. 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 The Line Method Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  8. 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. Properties for Axes and Labels Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  9. 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. Adding Division Marks and Labels Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  10. 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 Charts for Vintage Videos Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  11. 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. Steps for Creating Vintage Videos Charts Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  12. 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. Creating Line Charts Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  13. DrawStyle Property Constants and Values Line StyleVB ConstantValue Solid vbSolid 0 Dash vbDash 1 Dot vbDot 2 Dash Dot vbDashDot 3 Dash Dot Dot vbDashDotDot 4 Transparent vbTransparent 5 Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  14. 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. Creating Bar Charts Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  15. Fill StyleVB ConstantValue Solid vbFSSolid 0 Transparent vbFSTransparent 1 Horizontal Lines vbHorizontalLine 2 Vertical Lines vbVerticalLine 3 Upward Diagonal vbUpwardDiagonal 4 Downward Diagonal vbDownwardDiagonal 5 FillStyle Property Options Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  16. 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. Creating Pie Charts Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  17. 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 The Circle Method Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  18. Compute cumulative fractions for each of three types of videos. Set the coordinate system for the form. Draw pie chart using Circle method. Three Steps to Create Pie Chart for Vintage Videos Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

  19. 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. Creating Scatter Diagrams Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy

More Related