Click here to Skip to main content
15,868,016 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 587.6K   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

 
GeneralThe download link doesnt work Pin
javed008910-Dec-07 21:51
javed008910-Dec-07 21:51 
QuestionPossible for a web form application? Pin
adb95hxo30-Nov-07 5:55
adb95hxo30-Nov-07 5:55 
AnswerRe: Possible for a web form application? Pin
Member 35728712-May-08 4:26
Member 35728712-May-08 4:26 
AnswerRe: Possible for a web form application? Pin
euclides.lago21-Jan-09 6:41
euclides.lago21-Jan-09 6:41 
QuestionToolTip Text Pin
JonRoperUK22-Nov-07 2:02
JonRoperUK22-Nov-07 2:02 
Generalused as library and included in other project Pin
den.ria21-Nov-07 11:24
den.ria21-Nov-07 11:24 
GeneralRe: used as library and included in other project Pin
Adagio.8121-Nov-07 21:58
Adagio.8121-Nov-07 21:58 
GeneralRe: used as library and included in other project Pin
den.ria22-Nov-07 15:15
den.ria22-Nov-07 15:15 
GeneralRe: used as library and included in other project Pin
Adagio.8126-Nov-07 2:32
Adagio.8126-Nov-07 2:32 
GeneralRe: used as library and included in other project Pin
den.ria26-Nov-07 12:47
den.ria26-Nov-07 12:47 
GeneralRe: used as library and included in other project Pin
den.ria26-Nov-07 16:06
den.ria26-Nov-07 16:06 
GeneralRe: used as library and included in other project Pin
Adagio.8128-Nov-07 1:56
Adagio.8128-Nov-07 1:56 
GeneralRe: used as library and included in other project Pin
rmbsrichard9-Oct-08 12:42
rmbsrichard9-Oct-08 12:42 
GeneralRe: used as library and included in other project Pin
Rapunzo17-Dec-08 23:24
Rapunzo17-Dec-08 23:24 
Generalresize the image Pin
den.ria20-Nov-07 15:34
den.ria20-Nov-07 15:34 
GeneralRe: resize the image Pin
Adagio.8120-Nov-07 23:00
Adagio.8120-Nov-07 23:00 
GeneralRe: resize the image Pin
den.ria21-Nov-07 8:42
den.ria21-Nov-07 8:42 
GeneralRe: resize the image Pin
den.ria21-Nov-07 11:21
den.ria21-Nov-07 11:21 
QuestionProblem with ToolTipText? Pin
Kenn Minear19-Nov-07 16:51
Kenn Minear19-Nov-07 16:51 
AnswerRe: Problem with ToolTipText? Pin
Adagio.8120-Nov-07 22:58
Adagio.8120-Nov-07 22:58 
GeneralRe: Problem with ToolTipText? Pin
Kenn Minear4-Dec-07 21:29
Kenn Minear4-Dec-07 21:29 
GeneralMore Features Pin
Sorin Dolha27-Oct-07 0:01
Sorin Dolha27-Oct-07 0:01 
QuestionHow do I add this to a project? Pin
ItsBill18-Oct-07 9:41
ItsBill18-Oct-07 9:41 
AnswerRe: How do I add this to a project? Pin
Adagio.8121-Oct-07 20:58
Adagio.8121-Oct-07 20:58 
GeneralWow, Wonderfull Pin
Irwan Hassan13-Oct-07 2:23
Irwan Hassan13-Oct-07 2:23 

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.