Chapter 11 using visual basic to create graphics
Download
1 / 19

Chapter 11: Using Visual Basic to Create Graphics - PowerPoint PPT Presentation


  • 113 Views
  • Uploaded on

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.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' Chapter 11: Using Visual Basic to Create Graphics' - nola-joyner


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.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Chapter 11 using visual basic to create graphics
Chapter 11:Using Visual Basic to Create Graphics

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy


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 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


Types of business graphics

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


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.

Creating Business Graphics with VB

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy


Methods for drawing axes

The follow a six-step approach: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


The scale method

Scale( follow a six-step approach: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


The line method

Object.line ( follow a six-step approach: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


Properties for axes and labels

The follow a six-step approach: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


Adding division marks and labels

Determine the width of the label with the follow a six-step approach: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


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

Charts for Vintage Videos

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy


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.

Steps for Creating Vintage Videos Charts

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy


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.

Creating Line Charts

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy


Drawstyle property constants and values
DrawStyle Property Constants and Values points on the chart.

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


Creating bar charts

Bar charts are drawn using the points on the chart. 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


Fillstyle property options

Fill Style points on the chart. VB 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


Creating pie charts

Pie charts are drawn using the points on the chart. 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


The circle method

object points on the chart. .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


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.

Three Steps to Create Pie Chart for Vintage Videos

Introduction to Programming with Visual Basic 6.0 by McKeown and Piercy


Creating scatter diagrams

Scatter diagrams help the user look for patterns in data. videos.

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


ad