Hi
I have this chart with some data in it ranging for a few days. I need to have the XAxisLabel format set to something like this when zoomed out:
Label="{}{TimeStamp:dddd MMMM dd}"
But when I zoom in I want the time only
Label="{}{TimeStamp:T}"
Is this possible without too much code behind? I hope for a simple property I have overlooked :-)
Hello Genvej,
Thank you for your post. I have been looking into the functionality that you are trying to achieve and in order to avoid writing code in the code behind, I can suggest binding the Label property of the CategoryDateTimeXAxis to the WindowRect.Width property of the XamDataChart. The WindowRect property is representation of the visible part of the XamDataChart and the Width property of the WindowRect corresponds to the horizontal zoom, so binding the label to it will allows you to change the Label when the user is zooming the chart. In the binding you can use a converter in order to change the double value of the Width property to the appropriate format for the label. I have created a sample application for you that demonstrates how you can implement this approach.
Please let me know if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Great example. Adressed my question to perfection! Only problem is that I didnt explain it proper (sorry) Im interested in showing the label in days when the range is more than a day. And then when I zoom in and the scale is less than a day I want hours instead. The data are dynamic and some span several days others only for a few hours. The Window.Rectangle doesnt work for that I think. But we are close.
My original idea was to have an event on the chart which looks at the window max and min value and then do my formatting based on the result. I like your converters better and if you had an idea how to do it with that it would be much appreciated :-)
Thank you for your reply. I am very glad that the sample was helpful for you. I have further investigate this approach and if you wish to dynamically set the Label to show dates when the range of the axis is more than a day and to time when it is a day or less I can suggest binding the label to the axes itself, the XamDataChart and the WindowRect.Width of the XamDataChart, using a MultiBinding. Using the GetUnscaledValue method of the CategoryDateTimeXAxis, in the MultiValueConverter, you can get the actual minimum and maximum value that is displayed in the CategoryDateTimeXAxis. After getting the min and max date you can see what is the amount of days that this interval covers and return the appropriate value for the Label property. Here is the how you can get the values in the converter:
C#:
public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture) { CategoryDateTimeXAxis axis = values[0] as CategoryDateTimeXAxis; XamDataChart chart = values[1] as XamDataChart; var viewport = new Rect( 0, 0, axis.ActualWidth, chart.Axes.OfType<NumericYAxis>().First().ActualHeight); var window = chart.WindowRect; //Getting the minimum displayed datetime var minVal = axis.GetUnscaledValue(0, new ScalerParams(window, viewport, axis.IsInverted)); DateTime min = new DateTime((long)minVal); //Getting the maximum displayed datetime var maxVal = axis.GetUnscaledValue(axis.ActualWidth, new ScalerParams(window, viewport, axis.IsInverted)); DateTime max = new DateTime((long)maxVal); //Calculating the range, coverted by the axis TimeSpan axisRange = max - min; if (axisRange.Days > 0) return "{Date:dddd MMMM dd}"; else return "{Date:T}"; }
I have modified the sample application I have sent you in order to demonstrates this approach.
This solution is what I was looking for in my application. However I need my label to change as the user changes the zoomBar. How can I force the Label to rebind so that the Binding Converter is called.
Hello Solomonfried,
Thank you for your reply. I have been looking into your quesiton and the label binding is triggered when the the zooming of the XamDataChart is changed. When you change the zoom level with the zoombars of the XamDataChart the label binding is also triggered. I assume that you wish to have the labels updated immediately when you start dragging the zoombar. If this is correct, you can do that by setting the WindowsResponce property of the XamDataChart to Immediate. Setting this property will force the XamDataChart to change the zooming immediately when you start changing the zoom level from the zoombar. I have modified the sample application that I have previously attached to the thread and also created a video of the result.
Krasimir, MCPD
Developer Support Supervisor - XAML