Xceed Chart for WinForms v4.4 Documentation
Welcome to Xceed Chart for WinForms v4.4 / User Guide / Axes / Scaling / Date Time Scale

In This Topic
    Date Time Scale
    In This Topic

    Date-time scale mode is often used as an alternative to the default scale mode (Dimension) of the PrimaryX and SecondaryX chart axes (for details, see StandardAxis Enumeration). When operating in this mode, the axes treat the values contained in the data series as date-time values. 

    The properties of the date-time scale are controlled through an instance of the AxisScaleDateTime class, which is accessible through the DateTimeScale property of the Axis class. The AxisScaleDateTime class is a direct descendant of the AxisScaleValue class and inherits all its functionality. It also implements control over the following aspects of a date time scale:

    Controlling Major Tick Generation in Date Time Scale Mode

    The user can control the mode in which major ticks are generated with the help of the MajorTickMode property which is of type MajorTickModeDateTime and can accept the following values (for details, see MajorTickModeDateTime Enumeration): 

    Manual
    Auto

    CustomStep

    IrregularSteps

    Months
     

    The following is a description of these modes:

    • Manual: When operating in this mode, the scale does not produce any ticks. It is up to the user to specify values on which major ticks should be displayed. The following code displays ticks on these date-time values: 21/1/2003, 1/2/2003, and 25/2/2003 of the PrimaryX axis:
    VB.NET  

    ' there is one chart created by default

    Dim chart As Chart = CType(chartControl1.Charts(0), Chart)

    Dim axis As Axis =   chart.Axis(StandardAxis.PrimaryX)

     

    axis.ScaleMode = AxisScaleMode.DateTime

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.Manual

    axis.MajorTicks.Clear()

     

    Dim dt As DateTime =  New DateTime(2003,1,21)

     

    axis.MajorTicks.Add(dt.ToOADate())

    dt = New DateTime(2003, 2, 1)

    axis.MajorTicks.Add(dt.ToOADate())

    dt = New DateTime(2003, 2, 25)

    axis.MajorTicks.Add(dt.ToOADate())

    C#  

    // there is one chart created by default

    Chart chart = (Chart)chartControl1.Charts[0];

    Axis axis = chart.Axis(StandardAxis.PrimaryX);

     

    axis.ScaleMode = AxisScaleMode.DateTime;

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.Manual;

    axis.MajorTicks.Clear();

     

    DateTime dt = new DateTime(2003, 1, 21);

     

    axis.MajorTicks.Add(dt.ToOADate());

    dt = new DateTime(2003, 2, 1);

    axis.MajorTicks.Add(dt.ToOADate());

    dt = new DateTime(2003, 2, 25);

    axis.MajorTicks.Add(dt.ToOADate());

    • Auto: Automatic mode produces automatic major ticks at equal intervals. The step is automatically determined. In this mode the user can control the density of the automatically generated major ticks with the help of the MaxTickCount property (inherited from AxisScaleValue). The following code instructs the PrimaryY axis to operate in Auto mode and generate no more than 10 major ticks regardless of the data scaled on it.
    VB.NET  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.Auto

    axis.DateTimeScale.MaxTickCount = 10

    C#  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.Auto;

    axis.DateTimeScale.MaxTickCount = 10;

    • Custom Step: Custom step mode produces automatic major ticks at equal intervals with user specified step. The step is controlled by the CustomStep property which is of type TimeSpan. The following code will force the date-time scale to produce major ticks with a step of 20 days, 4 hours and 3 minutes.
    VB.NET  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.CustomStep

    axis.DateTimeScale.CustomStep = New TimeSpan(20, 4, 3, 0)

    C#  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.CustomStep;
    axis.DateTimeScale.CustomStep = new TimeSpan(20, 4, 3, 0);

    • Irregular Steps: In this scaling mode, the scale produces automatic major ticks at irregular intervals. The user specifies a steps array through which the scale iterates. The following code will generate major ticks at irregular user defined intervals:
    VB.NET  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.IrregularSteps

    axis.DateTimeScale.CustomSteps.Clear()

    axis.DateTimeScale.CustomSteps.Add(TimeSpan.FromDays(20))

    axis.DateTimeScale.CustomSteps.Add(TimeSpan.FromDays(10))

    axis.DateTimeScale.CustomSteps.Add(TimeSpan.FromDays(15))

    C#  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.IrregularSteps;

    axis.DateTimeScale.CustomSteps.Clear();

    axis.DateTimeScale.CustomSteps.Add(TimeSpan.FromDays(20));

    axis.DateTimeScale.CustomSteps.Add(TimeSpan.FromDays(10));

    axis.DateTimeScale.CustomSteps.Add(TimeSpan.FromDays(15));

    • Months: In this mode, the scale produces automatic major ticks at month intervals. The user specifies the month step with the MonthsStep property.

      This scale mode will preserve the month ends. For example, if the scale begins at 1/31/2003 (end of January) and MonthsStep is set to 1, the generated ticks will be:

      1/31/2003, 2/28/2003 (end of February), 3/31/2003 (end of March), 4/30/2003 (end of April) ...

      On the other hand, if the scale begins at 1/30/2003 (not the month end), the generated ticks will be:

      1/30/2003, 2/28/2003 (day clamped to largest possible), 3/28/2003 (only month increased), 4/28/2003 (only month increased) ...

      The following code instructs the date time scale to generate ticks on each third month:
    VB.NET  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.Months

    axis.DateTimeScale.MonthsStep = 3

    C#  

    axis.DateTimeScale.MajorTickMode = MajorTickModeDateTime.Months;

    axis.DateTimeScale.MonthsStep = 3;

     

    Demonstration of the DateTime Major Tick modes
    Manual Auto
    Custom Step
    (in this case 20 days)
    Irregular Steps
    (in this case 20, 30, 15 days)
    Months
    (note that the scale preserves the month end)

     

     

     

    Related Examples

    Windows Forms: Axes\Scaling\DateTime Scale

    See Also

    Axis | AxisScale | AxisScaleValue | AxisScaleDateTime