buy now
log in

Q: I want to display DateTime values at the chart axis. I use numbers for the points but I don’t want to show this data, I want to show the DateTime values that come with it. Is this possible with your tool?

A: Charting for Wpf supports drawing custom labels on any chart axis. Custom labels can be drawn both at the positions of the intervals at the axis or at the position of the data points for this axis.

In your case we assume you want to draw DateTime labels taken from a data source at the position of the data points for the axis. Here is your code:

//set the data source
 lineChart1.DataSource = data;

 //set the name of the property in the data source to bind to
 lineChart1.XLabelPath = "PurchaseDate";

 //set the type of the labels for the X-axis
 lineChart1.XAxisSettings.LabelType = LabelType.CustomText; 
 //set the position of the custom labels
 lineChart1.XAxisSettings.CustomLabelPosition = CustomLabelPosition.ChartDataPoints;

 //set the format of the labels
 lineChart1.XAxisSettings.LabelFormat = "MMMM dd";

Note that it is very important to set the format of the labels. If you don’t do it, the control will try to convert your DateTime values to strings using standard conversion and the result will not be as expected.

Copyright © 2001-2019 MindFusion LLC. All rights reserved.
Terms of Use - Contact Us