Work Time and Workday Configuration
- 4 minutes to read
This document explains how to exclude non-working days and time from the date-time X-axis scale.
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 workdays options.
XYDiagram chartDiagram = (XYDiagram)financialChart.Diagram; DateTimeScaleOptions xAxisScaleOptions = chartDiagram.AxisX.DateTimeScaleOptions; // This property turns on weekends and holidays exclusion. xAxisScaleOptions.WorkdaysOnly = true; WorkdaysOptions workdayOptions = xAxisScaleOptions.WorkdaysOptions; // Specify which days of the week are treated as workdays. workdayOptions.Workdays = Weekday.Monday | Weekday.Tuesday | Weekday.Wednesday | Weekday.Thursday | Weekday.Friday; // Specify holiday dates. workdayOptions.Holidays.Add(new KnownDate("Christmas Eve", new DateTime(2017, 12, 24))); // Specify strict workdays dates. workdayOptions.ExactWorkdays.Add(new KnownDate("Custom Exact Workday", new DateTime(2017, 7, 24)));
The below 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 non-working days.|
|WorkdaysOptions.Workdays||Specifies which days of the week are workdays.|
|WorkdaysOptions.Holidays||Specifies holiday dates for excluding them from the date-time scale.|
|WorkdaysOptions.ExactWorkdays||Specifies strict workday dates for including them to the date-time scale.|
|KnownDate||A particular named date.|
Note that holidays can be imported from the DevExpress Scheduler (.xml) or Microsoft Office Outlook® (.hol) file, using the Load Holidays button, at design time, or using the WorkdaysOptions.LoadHolidays method at runtime.
You can also use the DateTimeScaleOptions.SkipRangesWithoutPoints property to exclude all date-time axis ranges without data points.
Exclude Non-Working Time
Work Time Rules allows you to specify time intervals which 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 that for weekdays, whose work time rules are not specified (e.g. Saturday and Sunday in the code above), the whole day (00:00 AM - 12:00 PM) is taken as work time.
To exclude whole days, use Workdays properties.
The code below uses the following classes and methods.
|Class or Member||Description|
|DateTimeScaleOptions.WorkTimeOnly||Specifies the value indicating whether to show only the working time on a date-time axis.|
|DateTimeScaleOptions.WorkTimeRules||Specifies a collection of work time rules which 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.|