$99 VS $1000+. UI Control for ASP.NET AJAX(contains chart and gridview).
Chart Control for C# Windows Forms
Design Bar, Pie, Line, Area, Polar, Radar and Scatter for C# Windows Forms application
Home > WinForms UI Controls > User Manual > Chart Axes DateTime in C#

Date Time Axis in Chart for WinForms C# Tutorial

Axes can be used to represent the collection of Data Time to sort data time value chronologically in Cartesian Area. There are 2 data time axes supported by Chart, DateTimeCategorical, which is a categorical axis and DateTimeContinuous, which is a numerical one, both of which sort their data chronologically. The following tutorial shows more details about the two data time axes.

Date Time Categorical Axis for Chart

The DateTime categorical axis, which is a categorical axis, sorts the values of Date Time chronologically. By using DateTime categorical axis, developers can define the category of particular date time like year, month, and day. The following are the key properties of the DateTime categorical axis.
  • DateTimeControl , this is a property used to control the component from the DateTime and is able to create categories. Its valid values include Date, Millisecond, Second, Minute, Hour, Day, Week, Month, Season, Year, Ticks, TimeOfDay, DayOfWeek, DayOfYear.
  • GapLength , this is a property used to configure the gap between the plotted Cartesian series position and the valid range value is from 0 to 1
  • PlotMode, the property is used to configure the value of AxisPlotMode that is used to plot the data by the axis. Its valid values include BetweenTicks, OnTicks, OnTicksPadded.
  • MainTickInterval, this is a property used to customize the step where ticks are located.
  • HPosition, the property is used to fix the position of the horizontal place of the axis against the plot area. Its valid values include Top and Bottom
  • VPosition, the property is used to fix the position of the vertical place of the axis in against the plot area. Its valid values include Left and Right.
In addition, DateTimeCategorical axis is not the default to Cartesian series. As the descendant of Axis, it will inherit all properties of the Axis class. Developers need to create an instance of this property and assign it to the series. The below C# code shows the steps.

LineSeries series = new LineSeries();
series.DataPoints.Add(new CategoricalDataPoint(12, DateTime.Now));
series.DataPoints.Add(new CategoricalDataPoint(3, DateTime.Now.AddDays(1)));
series.DataPoints.Add(new CategoricalDataPoint(4, DateTime.Now.AddDays(2)));
series.DataPoints.Add(new CategoricalDataPoint(7, DateTime.Now.AddDays(3)));

DateTimeCategoricalAxis categoricalAxis = new DateTimeCategoricalAxis();
categoricalAxis.DateTimeControl = DateTimeControl.Day;
categoricalAxis.PlotMode = AxisPlotMode.BetweenTicks;
categoricalAxis.LabelFormat = "{0:m}";

series.HorizontalAxis = categoricalAxis;
chart1.Series.Add(series);

DateTimeContinuous Axis for Chart

The DateTimeContinuous axis, which is a numerical axis, sorts the values of Date Time chronologically. The following are the key properties of the DateTime categorical axis.
  • MaxTicks, the property is used to set the maximum ticks that might be displayed on the axis.
  • MainStep, the property is used to set the step in the adjacent ticks on the axis.
  • MainStepUnit, this is a property used to specifies the measurement to configure the custom major step of the axis.
  • Mini, the property is used to set the minimum axis.
  • Max, the property is used to set maximum axis.
  • GapLength, this is a property used to configure the gap between the plotted Cartesian series position and the valid range value is from 0 to 1
  • PlotMode, the property is used to configure the value of AxisPlotMode that is used to plot the data by the axis. Its valid values include BetweenTicks, OnTicks, OnTicksPadded.
  • HLocation, the property is used to fix the position of the horizontal place of the axis against the plot area. Its valid values include Top and Bottom
  • VLocation, the property is used to fix the position of the vertical place of the axis in against the plot area. Its valid values include Left and Right.
In addition, DateTimeContinuous axis is not the default to Cartesian series. As the descendant of Axis, it will inherit all properties of the Axis class. Developers need to create an instance of this property and assign it to the series. The below C# code shows the steps.

LineSeries lineSeries = new LineSeries();
lineSeries.DataPoints.Add(new CategoricalDataPoint(9, DateTime.Now));
lineSeries.DataPoints.Add(new CategoricalDataPoint(2, DateTime.Now.AddDays(1)));
lineSeries.DataPoints.Add(new CategoricalDataPoint(3, DateTime.Now.AddDays(2)));
lineSeries.DataPoints.Add(new CategoricalDataPoint(7, DateTime.Now.AddDays(3)));

DateTimeContinuousAxis continuousAxis = new DateTimeContinuousAxis();
continuousAxis.PlotMode = AxisPlotMode.BetweenTicks;
continuousAxis.LabelFormat = "{0:d}";

lineSeries.HorizontalAxis = continuousAxis;
chart1.Series.Add(lineSeries);
UI Controlsfor Windows Forms
.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls