How to Create a Gantt Chart in VB Using a Graph Custom Control (112650)
The information in this article applies to:
- Microsoft Visual Basic Professional Edition for Windows 3.0
This article was previously published under Q112650 SUMMARY
A Gantt chart is a horizontal bar chart used for project planning and
reporting. The Graph custom control that comes with the Professional
Edition of Visual Basic for Windows can be used to create a Gantt chart.
This article shows by examnple how to create a Gantt chart.
MORE INFORMATION
To create a Gantt chart using the Graph custom control, you need to know
how many bars your graph will require. Typically this includes one project
bar and several activity bars. You will also need to know the number of
sections required in each bar. Typically each bar is divided into two
sections -- one to show actual progress on the project, the other to show
plans for the time remaining.
In the graph custom control, NumPoints represents the number of horizontal
bars needed, so the following is true:
NumSets = (Number of Bars) * (Sections on a Bar)
or
NumSets = NumPoints * (typically 2)
To make the graph more readable, you can set the range of the horizontal
axis using YAxisStylealong with YAxisMax. To place tick marks, use
YAxisTicks. To clear previous data assigned to the graph, use DataReset.
To plot the bars on the graph, you need to assign values to the GraphData
property of Graph1. GraphData values that follow ThisSet = 1 assignment
indicate the beginning of the section on a bar, and the corresponding
GraphData values following the ThisSet = 2 assignment, indicate the end of
the section. For example:
To plot the following Gantt chart:
| 5 7 11
1 | [------------]<-------------->
|
| 6 8 15
2 | [-----------]< --------------------->
|
|__________________________________________________
Make the following assignments:
Graph1.ThisSet = 1 ' Beginning of intervals
Graph1.GraphData = 5
Graph1.GraphData = 6
Graph1.GraphData = 7
Graph1.GraphData = 8
Graph1.ThisSet = 2 ' End of intervals
Graph1.GraphData = 7
Graph1.GraphData = 8
Graph1.GraphData = 11
Graph1.GraphData = 15
After assigning values to the graph, set the GraphType to 5 to indicate a
Gantt chart, and set GraphStyle to 1 if you want spaced bars. Set DrawMode
to 2 and DrawStyle to 1 if you want color.
Step-by-Step Example
This example creates the Gantt chart. - Start a new project in Visual Basic. Form1 is created by default.
- Place a graph control (Graph1) on Form1.
- Add the following code to the Form_Load event:
Sub Form_Load ()
Graph1.NumSets = 4
Graph1.YAxisStyle = 2
Graph1.YAxisMax = 20
Graph1.YAxisTicks = 10
Graph1.DataReset = 1
End Sub
- Add the following code to the Graph1_Click event:
Sub Graph1_Click ()
Graph1.ThisSet = 1 ' Set starting values for bar sections
Graph1.GraphData = 5 ' Left half
Graph1.GraphData = 6
Graph1.GraphData = 7 ' Right half
Graph1.GraphData = 8
Graph1.ThisSet = 2 ' Set ending values for bar sections
Graph1.GraphData = 7 ' Left half
Graph1.GraphData = 8
Graph1.GraphData = 11 ' Right half
Graph1.GraphData = 15
Graph1.GraphType = 5
Graph1.GraphStyle = 1
Graph1.DrawMode = 2
Graph1.DrawStyle = 1
End Sub
- Run the program, and click the graph.
Modification Type: | Minor | Last Reviewed: | 1/8/2003 |
---|
Keywords: | KB112650 |
---|
|