Gantt Chart Tip: Scrolling Time Scale Below Fixed Date Line

Posted by Alfred Göhlich on Aug 28, 2014 10:41:00 AM
Here comes another tip of how to make your Gantt chart developed with our VARCHART XGantt winforms even more vivid: Create Gantt charts that allow to shift the time scale and bars automatically from right to left - similar to an animated banner. This is done by displaying a scrolling time scale below a fixed date line.

Create a System.Windows.Forms.Timerobject that executes the following code on each Tick event:

DateTime leftDate = DateTime.MinValue;
DateTime rightDate = DateTime.MinValue;   

VcDateLine dl1 = vcGantt1.DateLineCollection.DateLineByName("DateLine_1-1");
vcGantt1.GetCurrentViewDates(ref leftDate, ref rightDate);  

if (vcGantt1.TimeScaleEnd <= rightDate.AddMinutes(2))
    vcGantt1.TimeScaleEnd = vcGantt1.TimeScaleEnd.AddHours(1);

DateTime newLeftDate = leftDate.AddHours(1);
DateTime newDateLineDate = dl1.Date.AddHours(1);  

dl1.Visible = false;  
vcGantt1.ScrollToDate(newLeftDate, VcHorizontalAlignment.vcLeftAligned, 0);

dl1.Date = newDateLineDate;

dl1.Visible = true;

This code will cause the time scale to shift to the next hour on each Tick event. The temporal position of the date line can be set at design time on the XGantt property pages or with the VcDateLine.Date property when starting the program.


This tip gave you an idea of how to quickly and simply improve the interaction experience in your Gantt chart. Interested in more tips and tricks? Find this and 10 more best practice Gantt visualization tips put together in an ebook that you can download for free! 


Ebook- 11 Best Practice Tips for Advanced Gantt Visualization

Topics: Windows Forms Gantt Control, XGantt development tricks, Gantt Best Practice, Gantt Chart Controls