Click here to Skip to main content
15,881,027 members
Articles / Programming Languages / Visual Basic
Article

Gantt Chart

Rate me:
Please Sign up or sign in to vote.
4.75/5 (80 votes)
2 Oct 2008CPOL2 min read 590.1K   38.1K   254   171
Adds an easy to use Gantt chart to your application.

GanttChart.JPG

Introduction

This component makes it easy to add a Gantt chart to your application. You just need three lines of code to get it working.

This Gantt chart control includes these features:

  • The columns are automatically shown based on the width of the component and the time between the start date and the end date. If there're more than two days between those dates, it will only show the date; otherwise, it will show the time of the day (with minimum 5 minutes apart).
  • You can set the color (including the hover color) for each bar individually.
  • The Gantt chart automatically shows a custom scroll bar when it contains more rows than the visible area allows.
  • You can easily obtain information about the bar when hovering your mouse above one.
  • An easy to use multi-row tooltip text.
  • Change bars using your mouse.

Background

I tried to find a good, free, and easy Gantt chart control to use in my project, but didn't have any luck. Then, I decided to make one myself, which actually was easier than I thought it would be.

Using the code

To get the Gantt chart component to show something, you only need this:

VB
GanttChart1.FromDate = New Date(2007, 12, 12, 0, 0, 0)
GanttChart1.ToDate = New Date(2007, 12, 24, 0, 0, 0)
GanttChart1.AddChartBar("Row 1", Nothing, New Date(2007, 12, 12), 
    New Date(2007, 12, 16), Color.Aqua, Color.Khaki, 0))

As mentioned above, this component also includes a multi-line tooltip text.

VB
With GanttChart2
  Dim toolTipText As New List(Of String)
  toolTipText.Add("Time:")

  .ToolTipTextTitle = .MouseOverRowText
  .ToolTipText = toolTipText
 
End With

When a tooltip-text-row is included, the line is automatically bolded.

It is also possible to save the Gantt Chart to an image file:

VB
GanttChart2.SaveImage("C:\TestImage.jpg")

The included Zip file contains a project showing how to use its different features.

History

  • Version 0.55
    • Added the feature to drag the bars (after editing a bar, a BarChanged event is fired).
    • If time between start and end date is larger than 60 days, the Gantt chart switches over to showing months instead of days.
  • Version 0.54
    • The Gantt chart can now be saved to an image file.
  • Version 0.53
    • ScrollBar added to component.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Denmark Denmark
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralRe: Great Job.... Pin
Adagio.8113-Jul-11 0:55
Adagio.8113-Jul-11 0:55 
GeneralMy vote of 5 Pin
weichiang333-May-11 16:17
weichiang333-May-11 16:17 
GeneralRe: My vote of 5 Pin
Adagio.8113-Jul-11 0:55
Adagio.8113-Jul-11 0:55 
GeneralI need this code for c#,who can help me to convent this code ?thanks! Pin
cnsdn2-Apr-11 15:09
cnsdn2-Apr-11 15:09 
GeneralVery good ! Pin
Paulo Viana25-Jan-11 1:13
Paulo Viana25-Jan-11 1:13 
GeneralGreat control Pin
vliexr28-Oct-10 4:58
vliexr28-Oct-10 4:58 
QuestionChange bar with mouse? Pin
vjcoppola22-Jul-10 5:33
vjcoppola22-Jul-10 5:33 
Generalabout ticks Pin
kf6130921-Jul-10 9:36
kf6130921-Jul-10 9:36 
GeneralVery Nice but missing horizontal scrollbar Pin
InvincibleAngel5-Jun-10 9:08
InvincibleAngel5-Jun-10 9:08 
GeneralRe: Very Nice but missing horizontal scrollbar Pin
MicheleLaPietra16-Jun-10 4:12
MicheleLaPietra16-Jun-10 4:12 
GeneralRe: Very Nice but missing horizontal scrollbar Pin
Adagio.8117-Jun-10 2:35
Adagio.8117-Jun-10 2:35 
GeneralRe: Very Nice but missing horizontal scrollbar Pin
TritonKeyboarder23-Sep-11 1:33
TritonKeyboarder23-Sep-11 1:33 
GeneralRe: Very Nice but missing horizontal scrollbar Pin
fk_nirvana25-Jun-13 10:57
fk_nirvana25-Jun-13 10:57 
GeneralRe: Very Nice but missing horizontal scrollbar Pin
fk_nirvana25-Jun-13 10:58
fk_nirvana25-Jun-13 10:58 
QuestionHow add Gant Chart ? Pin
boydevelop21-May-10 5:47
boydevelop21-May-10 5:47 
QuestionIs new version available? Pin
Member 333222823-Mar-10 0:41
Member 333222823-Mar-10 0:41 
AnswerRe: Is new version available? Pin
Adagio.8126-Mar-10 2:31
Adagio.8126-Mar-10 2:31 
GeneralGood job! Pin
Shane Story27-Jan-10 6:39
Shane Story27-Jan-10 6:39 
GeneralRe: Good job! Pin
Adagio.8126-Mar-10 2:31
Adagio.8126-Mar-10 2:31 
QuestionHow to add this to C# Project? Pin
boakineo8-Jan-10 20:47
boakineo8-Jan-10 20:47 
GeneralCannot Access Pin
khanlon195118-Nov-09 10:14
khanlon195118-Nov-09 10:14 
GeneralRe: Cannot Access Pin
Adagio.8126-Mar-10 2:32
Adagio.8126-Mar-10 2:32 
GeneralAlso a movable time bar would be great. Pin
Pete_1-Nov-09 4:15
Pete_1-Nov-09 4:15 
QuestionTime based, how possible? Pin
Pete_1-Nov-09 4:12
Pete_1-Nov-09 4:12 
GeneralVery nice Pin
hairy_hats30-Jun-09 1:49
hairy_hats30-Jun-09 1:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.