MindFusion.Charting for Silverlight Programmer's Guide
DateTime Values

  1. If you want to use DateTime values as X, Y, X2 or Y2 data for your chart you do that the same was as you'd add numeric values. MindFusion.Charting for Silverlight supports DateTime values given in any of these formats:

C#  Copy Code

DateTime myDateTime = new DateTime(2011, 12, 1);
lineSeries[0].XData.Add(myDateTime.ToOADate());

VB.NET  Copy Code

Dim myDateTime As New DateTime(2011, 12, 1)
lineSeries(0).XData.Add(myDateTime.ToOADate())

C#  Copy Code

DateTime myDateTime = new DateTime(2011, 12, 1);
lineSeries[0].XData.Add(myDateTime);

VB.NET  Copy Code

Dim myDateTime As New DateTime(2011, 12, 1)
lineSeries(0).XData.Add(myDateTime)

C#  Copy Code

DateTime myDateTime = new DateTime(2011, 12, 1);
lineSeries[0].XData.Add(myDateTime.Ticks);

VB.NET  Copy Code

Dim myDateTime As New DateTime(2011, 12, 1)
lineSeries(0).XData.Add(myDateTime.Ticks)

  1. You must set the ValueFormat property of the AxisSettings object for the axis at which DateTime data will be shown to ValueFormat.DateTime:

C#  Copy Code

lineChart1.XAxisSettings.ValueFormat = ValueFormat.DateTime;

VB.NET  Copy Code

lineChart1.XAxisSettings.ValueFormat = ValueFormat.DateTime

  1. The start and end values of the respective axis must be set to the desired DateTime value. The properties for that - AxisSettings.MinValue and AxisSettings.MaxValue accept only double values. When the AxisSettings.ValueFormat is ValueFormat.DateTime the control expects OLE Automation representation of the values for the properties:

C#  Copy Code

DateTime start = new DateTime(2011, 3, 1);
DateTime end = new DateTime(2011, 10, 31);
lineChart1.XAxisSettings.MinValue = start.ToOADate();
lineChart1.XAxisSettings.MaxValue = end.ToOADate();

VB.NET  Copy Code

Dim start As New DateTime(2011, 3, 1)
Dim [end] As New DateTime(2011, 10, 31)
lineChart1.XAxisSettings.MinValue = start.ToOADate()
lineChart1.XAxisSettings.MaxValue = [end].ToOADate()

  1. Set the interval. The size of the interval among the scale divisions of the axis depends on the number of divisions we want to see. In the following code the intervals are 10:

C#  Copy Code

lineChart1.XAxisSettings.Interval = (end.ToOADate() - start.ToOADate())/10;

VB.NET  Copy Code

lineChart1.XAxisSettings.Interval = ([end].ToOADate() - start.ToOADate()) / 10

  1. Format the labels. You must use the AxisSettings.LabelFormat property to specify how the chart will display the DateTime values.  All standard .NET format specifiers for DateTime values are supported:

C#  Copy Code

lineChart1.XAxisSettings.LabelFormat = "MM-dd-yy";

VB.NET  Copy Code

lineChart1.XAxisSettings.LabelFormat = "MM-dd-yy"

  1. Rotate the labels. If the labels are too long you can use the AxisSettings.LabelRotationAngle property to rotate them so they don't overlap:

C#  Copy Code

lineChart1.XAxisSettings.LabelRotationAngle = 35;

VB.NET  Copy Code

lineChart1.XAxisSettings.LabelRotationAngle = 35

Using DateTime values in a chart is shown in detail in the DateTimeValues sample that is installed with the control.