Articles in this section
Category / Section

How to work with date values in chart axes in WinForms Chart?

1 min read

Syncfusion® WinForms Charts, allow the chart axes to use dates as their value type. This functionality is controlled via the ValueType property.

To specify the range type of the axis, the RangeType property is used. You can set the date and time range using the DateTimeRange property, while the format of the date and time can be specified with the DateTimeFormat property. The interval type is determined by the IntervalType property.

C#

//Configure the chart series
ChartSeries chartSeries = new ChartSeries("YValue");
chartSeries.Type = ChartSeriesType.Line;

//Specify the IntervalType
this.chartControl1.PrimaryXAxis.ValueType = ChartValueType.DateTime;
this.chartControl1.PrimaryXAxis.IntervalType = ChartDateTimeIntervalType.Days;
this.chartControl1.PrimaryXAxis.EdgeLabelsDrawingMode = ChartAxisEdgeLabelsDrawingMode.Shift;

//Specify the RangeType
this.chartControl1.PrimaryXAxis.RangeType = ChartAxisRangeType.Set;
this.chartControl1.PrimaryXAxis.DateTimeRange = new ChartDateTimeRange(start, start.AddDays(42), 7, ChartDateTimeIntervalType.Days);
this.chartControl1.PrimaryXAxis.DateTimeInterval.Type = ChartDateTimeIntervalType.Days;
this.chartControl1.PrimaryXAxis.DateTimeFormat = "dd,MMM, dddd";

//Update the data points to the chart series
foreach (var data in dataSource)
{
    chartSeries.Points.Add(data.Date, data.YValue);
}
this.chartControl1.Series.Add(chartSeries);

VB

'Configure the Chart Series
Dim start As New DateTime(1999, 1, 1)
Dim chartSeries As New ChartSeries("YValue")
chartSeries.Type = ChartSeriesType.Line

'Specify the Interval Type
columnChart.PrimaryXAxis.ValueType = ChartValueType.DateTime
columnChart.PrimaryXAxis.IntervalType = ChartDateTimeIntervalType.Days
columnChart.PrimaryXAxis.EdgeLabelsDrawingMode = ChartAxisEdgeLabelsDrawingMode.Shift;

'Specify the Range Type
columnChart.PrimaryXAxis.RangeType = ChartAxisRangeType.Set
columnChart.PrimaryXAxis.DateTimeRange = New ChartDateTimeRange(start, start.AddDays(42), 7, ChartDateTimeIntervalType.Days)
columnChart.PrimaryXAxis.DateTimeInterval.Type = ChartDateTimeIntervalType.Days
columnChart.PrimaryXAxis.DateTimeFormat = "dd,MMM, dddd"

'Update the data point to the series points
For Each salesData In dataSource
    chartSeries.Points.Add(salesData.Date1, salesData.YValue)
Next
columnChart.Series.Add(chartSeries)

Output:

date values in chart axes


Conclusion

I hope you enjoyed learning about how to work with Date values in chart axes in WinForms Chart.

You can refer to our WinForms Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms Chart examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you! 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied