Click here to Skip to main content
15,861,168 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 586.7K   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

 
GeneralMy vote of 5 Pin
Member 851706114-Dec-20 5:16
Member 851706114-Dec-20 5:16 
GeneralRe: My vote of 5 Pin
Member 1502299823-Dec-20 3:18
Member 1502299823-Dec-20 3:18 
GeneralRe: My vote of 5 Pin
Member 851706124-Dec-20 21:54
Member 851706124-Dec-20 21:54 
QuestionLoop through bar information for all time in row Pin
Knight school4-Dec-18 9:26
Knight school4-Dec-18 9:26 
GeneralBest Project ever Pin
Member 101946779-Jul-18 7:32
Member 101946779-Jul-18 7:32 
QuestionRefresh bars Pin
Member 1184484022-Jun-18 11:28
Member 1184484022-Jun-18 11:28 
QuestionHow to get the last .totime of the bar, so that the next bar will start in the .totime of the last bar... Pin
Member 1356378822-Dec-17 6:38
Member 1356378822-Dec-17 6:38 
Questionhow to set 8 hours per day Pin
Member 1356378813-Dec-17 10:53
Member 1356378813-Dec-17 10:53 
QuestionHow can i have databind? like this GanttChart1.DataSource = ObjDS.Tables(0) Pin
Member 135637888-Dec-17 13:04
Member 135637888-Dec-17 13:04 
GeneralMy vote of 5 Pin
oli_the_true_one5-Nov-17 6:03
oli_the_true_one5-Nov-17 6:03 
QuestionHow can I add GanttChart3 to the form using Formdesigner Pin
Member 1331203316-Jul-17 4:49
Member 1331203316-Jul-17 4:49 
QuestionHorizontal Scrollbar // Strange Behaviour concerning time Pin
Member 977461413-May-17 5:05
Member 977461413-May-17 5:05 
QuestionControl Pin
Member 300148524-Mar-17 23:28
Member 300148524-Mar-17 23:28 
QuestionIs it possible to use this library in a C# (WPF) project?? Pin
Member 124167409-Mar-17 6:47
Member 124167409-Mar-17 6:47 
QuestionHow can I add a real-time vertical bar into it?? Pin
Member 129744392-Feb-17 6:39
Member 129744392-Feb-17 6:39 
Questionnew value of b.barinformation Pin
Member 387160216-Dec-16 9:11
Member 387160216-Dec-16 9:11 
Questionthee new value of the startime Pin
Member 387160216-Dec-16 9:11
Member 387160216-Dec-16 9:11 
QuestionHow to refresh ChartGantt ? Pin
sylvain_celio25-May-16 23:36
sylvain_celio25-May-16 23:36 
AnswerRe: How to refresh ChartGantt ? Pin
chrisbray9-Jun-16 3:10
chrisbray9-Jun-16 3:10 
GeneralRe: How to refresh ChartGantt ? Pin
Member 1208817412-Jan-17 5:49
Member 1208817412-Jan-17 5:49 
GeneralRe: How to refresh ChartGantt ? Pin
Member 1208817412-Jan-17 6:17
Member 1208817412-Jan-17 6:17 
QuestionF-Secure Flags this as a virus Pin
Member 1240640114-Apr-16 2:25
Member 1240640114-Apr-16 2:25 
Questionextend the bar till the end of todate? Pin
billcodes21-Mar-16 2:21
billcodes21-Mar-16 2:21 
QuestionHow do I add this control to my project? Pin
Tater_Schroeder19-Jan-16 2:28
Tater_Schroeder19-Jan-16 2:28 
AnswerRe: How do I add this control to my project? Pin
chrisbray9-Jun-16 3:17
chrisbray9-Jun-16 3:17 

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.