Work Time and Workday Configuration
- 5 minutes to read
This document explains how to exclude non-working days and time from the date-time X-axis scale. You will also find information on how to exclude all date-time axis ranges without data points.
Exclude Non-Working Days
Use Workdays Options to exclude non-working days or add strict workdays.
Axis.DateTimeScaleOptions.WorkdaysOnly = false | Axis.DateTimeScaleOptions.WorkdaysOnly = true |
---|---|
The following code demonstrates how to configure workday options:
Series series1 = chartControl1.Series[0];
series1.ArgumentScaleType = ScaleType.DateTime;
series1.DataSource = CreateChartData();
series1.SetFinancialDataMembers("Argument", "Low", "High", "Open", "Close");
DateTimeScaleOptions dateTimeScaleOptions = ((XYDiagram)chartControl1.Diagram).AxisX.DateTimeScaleOptions;
// Enables workday options.
dateTimeScaleOptions.WorkdaysOnly = true;
// Specifies custom work days.
// In this example, Sunday is a work day and Saturday is a day off.
dateTimeScaleOptions.WorkdaysOptions.Workdays = Weekday.Sunday | Weekday.Monday | Weekday.Tuesday |
Weekday.Wednesday | Weekday.Thursday | Weekday.Friday;
// Specifies custom holidays.
// In this example, March 8th (Monday) is an additional holiday.
dateTimeScaleOptions.WorkdaysOptions.Holidays.Add(
new KnownDate("Custom Holiday", new DateTime(2021, 3, 8, 0, 0, 0, 0)));
// Specifies work days, which have priority over specified holidays.
// In this example, March 6th (Saturday) is an additional work day.
dateTimeScaleOptions.WorkdaysOptions.ExactWorkdays.Add(
new KnownDate("Community Work Day", new DateTime(2021, 3, 6, 0, 0, 0, 0)));
The following members and classes are used in the code above:
Class or Member | Description |
---|---|
DateTimeScaleOptions.WorkdaysOnly | Specifies whether holidays and non-working days should be excluded from the axis scale. |
DateTimeScaleOptions.WorkdaysOptions | Specifies information about working days. |
WorkdaysOptions.Workdays | Specifies which days of the week are workdays. |
WorkdaysOptions.Holidays | Specifies holiday dates to be excluded from the date-time scale. |
WorkdaysOptions.ExactWorkdays | Specifies strict workday dates to be included in the date-time scale. |
KnownDate | A specific named date. |
Note that you can import holidays from a DevExpress Scheduler (.xml) or Microsoft Office Outlook® (.hol) file. Use the Load Holidays button at design time, or the WorkdaysOptions.LoadHolidays method at runtime.
Exclude Non-Working Time
Work Time Rules allow you to specify time intervals that should be displayed on the axis. The following table demonstrates this feature in action.
Axis.DateTimeScaleOptions.WorkTimeOnly = false | Axis.DateTimeScaleOptions.WorkTimeOnly = true |
---|---|
The following code demonstrates how to configure work time rules.
XYDiagram chartDiagram = (XYDiagram)financialChart.Diagram;
DateTimeScaleOptions xAxisScaleOptions = chartDiagram.AxisX.DateTimeScaleOptions;
// This property turns on axis values filtering by rules.
xAxisScaleOptions.WorkTimeOnly = true;
// Create a new instance of the worktime rule which will be used to specify
// the worktime displayed on the X-axis.
WorkTimeRule weekdayRule = new WorkTimeRule();
xAxisScaleOptions.WorkTimeRules.Add(weekdayRule);
// Specify one or more work intervals of this rule.
weekdayRule.WorkIntervals.Add(new TimeInterval(09, 00, 00, 19, 00, 00));
// Add weekdays on which this rule should be applied.
weekdayRule.Weekdays = Weekday.Monday | Weekday.Tuesday | Weekday.Wednesday
| Weekday.Thursday | Weekday.Friday;
WorkTimeRule dateRule = new WorkTimeRule();
xAxisScaleOptions.WorkTimeRules.Add(dateRule);
dateRule.WorkIntervals.Add(new TimeInterval(12, 00, 00, 16, 00, 00));
// Besides Weekdays, you can specify the Date
// on which this rule should be applied.
dateRule.Date = new DateTime(2017, 1, 1);
Note
If you don’t specify work time rules for certain days, the work time is the entire 24-hour day.
The code below uses the following classes and methods.
Class or Member | Description |
---|---|
DateTimeScaleOptions.WorkTimeOnly | Specifies the value indicating whether to show only the work time on a date-time axis. |
DateTimeScaleOptions.WorkTimeRules | Specifies a collection of work time rules that should be applied to the date-time axis scale. |
WorkTimeRule | A work time rule. |
WorkTimeRule.WorkIntervals | Specifies working intervals within a day. |
TimeInterval | A time interval. |
WorkTimeRule.Weekdays | Specifies weekdays on which the rule should be applied. |
WorkTimeRule.Date | Specifies the date on which the rule should be applied. |
Exclude Axis Ranges without Data
Use the DateTimeScaleOptions.SkipRangesWithoutPoints option to exclude all date-time axis ranges without data points. If your goal is to display work days/time only, enable the DateTimeScaleOptions.WorkdaysOnly and DateTimeScaleOptions.WorkTimeOnly properties instead.
The following images show a chart with different SkipRangesWithoutPoints values:
Property Value | Example |
---|---|
SkipRangesWithoutPoints = true | |
SkipRangesWithoutPoints = false (Default) |
Example
The following example demonstrates how you can exclude weekends and holidays from the X-axis range: