Back to Devexpress

WorkdaysOptions.Holidays Property

corelibraries-devexpress-dot-xtracharts-dot-workdaysoptions-15f2288d.md

latest5.7 KB
Original Source

WorkdaysOptions.Holidays Property

Specifies holidays for excluding them from the date-time axis scale.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[PersistenceMode(PersistenceMode.InnerProperty)]
public KnownDateCollection Holidays { get; }
vb
<PersistenceMode(PersistenceMode.InnerProperty)>
Public ReadOnly Property Holidays As KnownDateCollection

Property Value

TypeDescription
KnownDateCollection

A KnownDateCollection object, that stores the information about holidays.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to Holidays
DateTimeScaleOptions

.WorkdaysOptions .Holidays

|

Remarks

Use the Holidays property, to manually populate the collection of holidays.

Alternatively, you can import holidays in the DevExpress Scheduler ( .xml ) or Microsoft Office Outlook® ( .hol ) formats from a file, via the WorkdaysOptions.LoadHolidays method.

Note

If a date is defined as both a holiday (via the Holidays property) and strict workday (via the WorkdaysOptions.ExactWorkdays property), it is considered working day, and, consequently, it is not excluded from the axis scale.

For more information, refer to Data Aggregation.

Example

This example demonstates how to exclude non-working days (weekdays and holidays) from an axis range, with the DateTimeScaleOptions.WorkdaysOnly and DateTimeScaleOptions.WorkdaysOptions properties.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/winforms-chart-exclude-weekends-and-holidays-from-the-axis-range

csharp
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...
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)));
vb
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...
Dim dateTimeScaleOptions As DateTimeScaleOptions = CType(chartControl1.Diagram, XYDiagram).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 Or Weekday.Monday Or Weekday.Tuesday Or Weekday.Wednesday Or Weekday.Thursday Or Weekday.Friday

' Specifies custom holidays.
' In this example, March 8th (Monday) is an additional holiday.
dateTimeScaleOptions.WorkdaysOptions.Holidays.Add(New KnownDate("Custom Holiday", New Date(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 Date(2021, 3, 6, 0, 0, 0, 0)))

See Also

LoadHolidays

ExactWorkdays

Data Aggregation

How to: Exclude Weekends and Holidays from the Axis Scale

WorkdaysOptions Class

WorkdaysOptions Members

DevExpress.XtraCharts Namespace