Custom Time Scale Headers
If the built-in headers ranging from Minutes to Years are not sufficient, you can create custom headers with custom ranges as follows.
Step 1: Define the custom header and add it to the headers collection
// Custom Semester (Half-Yearly) header.
TimeScaleHeaderDefinition semesterHeader = new TimeScaleHeaderDefinition() {Name="Semester", Type = TimeScaleType.Custom, CustomTimeScaleTypeHint = new CustomTimeScaleTypeHint(6, TimeScaleType.Months) };
semesterHeader.ProvideCustomTimeIntervals += new ProvideCustomTimeIntervalsEventHandler(MainPage_ProvideSemesterHeaderTimeIntervals);
semesterHeader.ProvideCustomHeaderText += new ProvideCustomHeaderTextEventHandler(MainPage_ProvideSemesterHeaderText);ProvideCustomTimeIntervalsEventArgs args)
{
this.ganttControl.TimeScaleHeaders.Add(semesterHeader);
See how it's important to specify an approximate "hint" for the gantt to be able render this properly.
Step 2: Provide the custom intervals for this header for a given time span
void MainPage_ProvideSemesterHeaderTimeIntervals(object sender,
DateTime start = args.ViewStartTime;
if (args.ViewStartTime.Month < 7)
start = new DateTime(start.Year, 7, 1, 0, 0, 0, DateTimeKind.Utc);
else
start = new DateTime(start.Year + 1, 1, 1, 0, 0, 0, DateTimeKind.Utc);
// Prepare and return a list of custom time intervals for the current chart time span (args.ViewStartTime to args.ViewEndTime).
// This should be a list of DateTime values that indicate the start of each interval within the specified time span.
// args.ViewStartTime itself will be inserted to the front of this list, so you can choose to ignore it.
// Start of the intervals (spanning 6 months) within the time span are added to this list.
for (DateTime dateTime = start; dateTime <= args.ViewEndTime; dateTime = dateTime.AddMonths(6))
args.TimeIntervals.Add(dateTime);
}
Step 3: Provide the header text for this custom headers
void MainPage_ProvideSemesterHeaderText(object sender, ProvideCustomHeaderTextEventArgs args)
{
DateTime intervalStart = args.DateTime.Date;
// Ignore intervals that do not start on Jan 1st or July 1st.
if ((intervalStart.Month != 1 && intervalStart.Day != 1) || (intervalStart.Month != 6 && intervalStart.Day != 1))
{
args.Text = string.Empty;
return;
}
args.TooltipText = intervalStart.Year.ToString();
int half = ((intervalStart.Month - 1) / 6) + 1;
args.Text = "H" + half.ToString();// Displays H1 or H2
}
Here is the resultant custom header:
Custom Semester (half yearly) headers
� RadiantQ 2009 - 2019. All Rights Reserved.