CodeCentralShow Me

在 DevExpress Code Central 数据库中可以找到完整的示例项目,网址是 http://www.devexpress.com/example=E2365。 取决于目标平台类型 (ASP.NET、WinForms 等),可以在线运行本示例,或者下载自动可执行的示例。

本示例演示了如何从 轴范围 中去除非工作日 (周末和节假日),这是通过 AxisBase.WorkdaysOnlyAxisBase.WorkdaysOptions 属性来实现的。

C#CopyCode image复制代码
 (Form1.cs)
using System;
using System.Windows.Forms;
using DevExpress.XtraCharts;
// ...

AxisX axisX = ((XYDiagram)chartControl1.Diagram).AxisX;

// Exclude holidays from the axis scale.
axisX.WorkdaysOnly = true;

// Specify custom working days.
axisX.WorkdaysOptions.Workdays = Weekday.Sunday | Weekday.Monday | Weekday.Tuesday |
    Weekday.Wednesday | Weekday.Thursday | Weekday.Friday;

// Specify holidays
axisX.WorkdaysOptions.Holidays.AddRange(new KnownDate[] {
    new KnownDate("Custom Holiday 1", new DateTime(1994, 3, 2, 0, 0, 0, 0)),
    new KnownDate("Custom Holiday 2", new DateTime(1994, 4, 2, 0, 0, 0, 0))});

// Specify strict working days.
// Thay will have a priority over the holidays specified.
axisX.WorkdaysOptions.ExactWorkdays.Add(
    new KnownDate("Community Work Day", new DateTime(1994, 3, 2, 0, 0, 0, 0)));
Visual BasicCopyCode image复制代码
 (Form1.vb)
Imports System
Imports System.Windows.Forms
Imports DevExpress.XtraCharts
' ...

Dim axisX As AxisX = (CType(chartControl1.Diagram, XYDiagram)).AxisX

' Exclude holidays from the axis scale.
axisX.WorkdaysOnly = True

' Specify custom working days.
axisX.WorkdaysOptions.Workdays = Weekday.Sunday Or Weekday.Monday Or _ 
    Weekday.Tuesday Or Weekday.Wednesday Or Weekday.Thursday Or Weekday.Friday

' Specify holidays
axisX.WorkdaysOptions.Holidays.AddRange(New KnownDate() { _ 
    New KnownDate("Custom Holiday 1", New DateTime(1994, 3, 2, 0, 0, 0, 0)), _ 
    New KnownDate("Custom Holiday 2", New DateTime(1994, 4, 2, 0, 0, 0, 0))})

' Specify strict working days.
' Thay will have a priority over the holidays specified.
axisX.WorkdaysOptions.ExactWorkdays.Add(New KnownDate _ 
    ("Community Work Day", New DateTime(1994, 3, 2, 0, 0, 0, 0)))

下面的插图分别展示了含有非工作日、以及已去除非工作日的图表。

WorkdaysOnly = false

WorkdaysOnly = true

Expand image参阅