Back to Devexpress

DateTimeScaleOptions.WorkdaysOnly Property

corelibraries-devexpress-dot-xtracharts-dot-datetimescaleoptions-97dbbf27.md

latest7.4 KB
Original Source

DateTimeScaleOptions.WorkdaysOnly Property

Specifies whether holidays and non-working days should be excluded from the axis scale.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)]
public bool WorkdaysOnly { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Behavior)>
Public Property WorkdaysOnly As Boolean

Property Value

TypeDescription
Boolean

true to exclude non-working days from the axis scale; otherwise, false.

|

Property Paths

You can access this nested property as listed below:

Object TypePath to WorkdaysOnly
AxisBase

.DateTimeScaleOptions .WorkdaysOnly

|

Remarks

The WorkdaysOnly property is available for an axis if its scale type is date-time.

WorkdaysOnly = falseWorkdaysOnly = true

After the WorkdaysOnly property is enabled, the WorkdaysOptions property becomes available and you can specify non-working days, holidays and strict workdays for the axis scale.

You can also use the SkipRangesWithoutPoints property to skip axis ranges that do not have data points.

For more information, refer to the following topic: Data Aggregation.

The following example demonstrates how you can exclude weekends and holidays from the X-axis range:

View Example: Charts - How to exclude weekends and holidays from the axis range

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)))

The following code snippets (auto-collected from DevExpress Examples) contain references to the WorkdaysOnly property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/CS/DateTimeAggregation/Form1.cs#L259

csharp
private void checkEdit1_CheckedChanged(object sender, EventArgs e) {
    AxisX.DateTimeScaleOptions.WorkdaysOnly = ((CheckEdit)sender).Checked;
}

winforms-chart-exclude-weekends-and-holidays-from-the-axis-range/VB/WeekendsExclusion/Form1.vb#L29

vb
' Enables workday options.
dateTimeScaleOptions.WorkdaysOnly = True
' Specifies custom work days.

winforms-charts-use-automatic-date-time-scale-modes-of-an-axis/VB/DateTimeAggregation/Form1.vb#L251

vb
Private Sub checkEdit1_CheckedChanged(ByVal sender As Object, ByVal e As EventArgs)
    AxisX.DateTimeScaleOptions.WorkdaysOnly = CType(sender, CheckEdit).Checked
End Sub

See Also

DateTimeScaleOptions Class

DateTimeScaleOptions Members

DevExpress.XtraCharts Namespace