1. If you want to use DateTime values as X, Y or Y2 data for your chart you do that the same way as you would add numeric values. MindFusion.Charting for WPF supports DateTime values given in any of these formats:
C#
![]() |
---|
DateTime myDateTime = new DateTime(2011, 12, 1); |
VB.NET
![]() |
---|
Dim myDateTime As New DateTime(2011, 12, 1) |
C#
![]() |
---|
DateTime myDateTime = new DateTime(2011, 12, 1); |
VB.NET
![]() |
---|
Dim myDateTime As New DateTime(2011, 12, 1) |
C#
![]() |
---|
lineSeries[0].XData.Add(myDateTime.Ticks); |
VB.NET
![]() |
---|
lineSeries(0).XData.Add(myDateTime.Ticks) |
2. You must set the ValueFormat property of the Axis object for the respective X, Y, X2 or Y2 axis at which DateTime data will be shown to ValueFormat.DateTime:
C#
![]() |
---|
Axis xAxis = new Axis(); |
VB.NET
![]() |
---|
lineChart1.XAxisSettings.ValueFormat = ValueFormat.DateTime |
3. The start and end values of the respective axis must be set to the desired DateTime value. The properties for that - Axis.MinValue and Axis.MaxValue accept only double values. When the ValueFormat is ValueFormat.DateTime the control expects OLE Automation representation of the values for the properties:
C#
![]() |
---|
DateTime start = new DateTime(2011, 3, 1); |
VB.NET
![]() |
---|
Dim start As New DateTime(2011, 3, 1) |
The size of the interval among the scale divisions of the axis depends on the number of divisions we want to see:
C#
![]() |
---|
xAxis.Interval = (end.ToOADate() - start.ToOADate()) / 8; |
VB.NET
![]() |
---|
lineChart1.XAxisSettings.Interval = ([end].ToOADate() - start.ToOADate()) / 8 |
4. Then we select the type of labels to appear at the axis and rotate them at 35 degrees because formatted as DateTime values they are too long. We use the LabelRotationAngle property for that:
C#
![]() |
---|
xAxis.Interval = (end.ToOADate() - start.ToOADate())/8; |
VB.NET
![]() |
---|
lineChart1.XAxisSettings.Interval = ([end].ToOADate() - start.ToOADate()) / 8 |
5. Finally, don't forget to add the axis to the respective X/Y/X2/Y2 collection:
C#
![]() |
---|
myLineChart.XAxes.Add(xAxis); |
Using DateTime values in a chart is shown in detail in the DateTimeValues sample that is installed with the control.