Click here to Skip to main content
15,885,842 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 591K   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

 
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 
Thanks, saved me a mountain of coding. 5.


I hope you realise that hamsters are very creative when it comes to revenge. - Elaine

Generalc# Pin
Rapunzo17-Dec-08 21:33
Rapunzo17-Dec-08 21:33 
GeneralRe: c# Pin
kaborka26-May-09 14:36
kaborka26-May-09 14:36 
GeneralRe: c# Pin
overraider20-Nov-09 6:13
overraider20-Nov-09 6:13 
GeneralRe: c# Pin
kaborka26-Dec-09 9:58
kaborka26-Dec-09 9:58 
GeneralColumn question Pin
Salvatore Tipaldi22-Nov-08 22:05
Salvatore Tipaldi22-Nov-08 22:05 
GeneralRe: Column question Pin
Adagio.8126-Nov-08 20:38
Adagio.8126-Nov-08 20:38 
GeneralRe: Column question Pin
Salvatore Tipaldi26-Nov-08 22:35
Salvatore Tipaldi26-Nov-08 22:35 
GeneralRe: Column question Pin
Adagio.8127-Nov-08 22:37
Adagio.8127-Nov-08 22:37 
GeneralBug when resizing bars Pin
jose.mira23-Oct-08 0:57
jose.mira23-Oct-08 0:57 
GeneralThanks Pin
lymadalin6-Oct-08 17:44
lymadalin6-Oct-08 17:44 
Question[Feature Suggestion] Opening Ms Project XML Files. Pin
Danielku1521-Sep-08 5:41
Danielku1521-Sep-08 5:41 
QuestionTooltip text - not display when not over a bar Pin
thusitha@cs.auckland.ac.nz6-Sep-08 22:09
thusitha@cs.auckland.ac.nz6-Sep-08 22:09 
AnswerRe: Tooltip text - not display when not over a bar Pin
KihoC11-Oct-08 10:12
KihoC11-Oct-08 10:12 
AnswerRe: Tooltip text - not display when not over a bar Pin
Wade737-May-09 10:08
Wade737-May-09 10:08 
GeneralMS access Pin
johaver5-Aug-08 23:15
johaver5-Aug-08 23:15 
GeneralWeb Pin
User 69332230-Jul-08 5:39
User 69332230-Jul-08 5:39 
GeneralRefresh Gantt Chart Pin
UniBond7-Jun-08 8:49
UniBond7-Jun-08 8: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.