I have several charts which use a CategoryDateTimeXAxis to display historical and forecast sales data. I would like to place a marker (such as a red vertical line) on these charts to indicate the current date (and hence the boundary between historical data and forecast data). I think I should be able to do this using a CrosshairLayer with a fixed CursorPosition - however, I can't see how to calculate the cursor position that is equivalent to a particular date. Any suggestions?
Hello Gregorach,
Rather than utilizing the CrosshairLayer with a fixed CursorPosition, I would recommend utilizing the ValueOverlay in the XamDataChart. This allows you to draw a vertical or horizontal line at a point of your choosing in the chart, and you can read about use of ValueOverlays here: https://ko.infragistics.com/help/wpf/datachart-series-value-overlay.
In this case, you would define a ValueOverlay and point its Axis property at your CategoryDateTimeXAxis as this will designate that you want a vertical line. The Value in this case would be the Ticks of DateTime.Today, and so I would recommend that you define a DateTime property on your view model that is set to DateTime.Today and bind the Value of the ValueOverlay to <propertyName>.Ticks.
I have attached a sample project to demonstrate the above. I hope this helps.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Yes, that's done the trick nicely. Thanks again.