In my WPF XamDataChart I am using a ScatterLineSeries - plotting a value against time. I want to show time on the x axis and the value on the y axis.
For the ScatterLineSeries I must use NumericXAxis and NumericYAxis. I have done, converting the DateTime value to Ticks (I've also tried using .ToOADate() too) to get a numerical value from the DateTime.
The series line itself looks fine and what I expect, but the labels on the x axis show the value in ticks. I want to format this using the DateTime formatting (e.g. hh:mm:ss) to be something more meaningful.
How do I do this? I've tried setting the x axis Label member to lots of variations of "{}{:hh:mm:ss}", but none seem to work. Ideally I'd like to use an IValueConverter, which can convert the value in Ticks to a DateTime, then create a string from that. I'd also like to use an IValueConverter on the y axis too to convert some values to strings (e.g. 1 = Good, 2 = OK, 3 = Bad).
Thanks,
Mike
No problem, Mike! Let me know if you need any more info.
-Graham
Hi Graham,
Ah yes, I'd forgotten about the DataTemplate for labels. Phew. I eventually managed to get it working.
Thanks for quick reply,
Mike,
For this sort of thing you can specify a DataTemplate for the axis labels, and then specify a value converter in the binding.
Here's how you might approach converting the ticks to a formatted date time string given an IValueConverter that converts from tics to date time strings using the converter parameter as a format string:
<igChart:XamDataChart.Axes> <igChart:NumericXAxis x:Name="xAxis"> <igChart:NumericXAxis.Label> <DataTemplate> <TextBlock Text="{Binding Path=Item, Converter={StaticResource ticksConverter}, ConverterParameter='hh:mm:ss'}" /> </DataTemplate> </igChart:NumericXAxis.Label> </igChart:NumericXAxis> </igChart:XamDataChart.Axes>
Let me know if you need some further help with it. You could use a similar approach but a different value converter to convert to enumeration values.