Is there a way to force the x-axis to display labels at specific interval? For example if the x-axis is a DateTime and goes from 11:23AM to 1:39PM but I only want to show labels at 11:30, 11:45, 12:00, 12:15, etc, is there a way to do this?
At the moment, the way to solve this is to set the Axis.Unit to 15 minutes, then to round the Axis.Minimum value down to the nearest 15 minutes, e.g., if the x-axis needs to cover a period starting from 11:23AM, then rounding down to the nearest 15 minutes, we set the Axis.Minimum to 11:15AM. Then labels will occur at 11:15, 11:30, 11:45, etc.
Though that's not exactly the customization you described, additional customization features for things such as labels are always being considered as we plan future releases.
I tried to use the Unit, minimum, and maximum properties as you mentioned but it does not appear to be exposed on the DataChart object. Does this same suggestion also hold true for the XamDataChart (I am not using the XamWebChart)? The best I can come up with is the interval property which does not guarantee my label will be on the rounded time I am hoping for.
I am trying with both but I will use whichever one will work. Converting over to the CategoryDateTimeXAxis means I have to change several pieces of code including the code to determine the y values of all the series that you send me before as the caluclated x valse looks more like a DateTime in ticks rather than a collection index.
Is there a way to make either the CategoryXAxis or CategoryDateTimeXAxis have specific label intervals and values? I need something that I can configure to display round numbers at the interval. For example, if the datetime range is 11:23:12 to 11:35:56 I would like to have lables at 11:25:00, 11:30:00 and 11:35:00. If the range was 10:34:23 to 23:43:21 then 10:00:00, 14:00:00, 18:00:00, 22:00:00, and 02:00:00. At least something like that...
Is this possible with the XamDataChart?
The CategoryXAxis wants to display a label that is associated with an actual item. What do your datetime values look like for the axis? It won't do any interpolation, and it wont make items that have timestamps with a greater difference look further apart than items with timestamps that are closer together. Your timestamps are a category label of the data, not a value to be interpolated or realigned as far as the CategoryXAxis is concerned, and are treated the same way as "Cars", "Planes", "Automobiles".
If you evenly space your timestamp values for your items, and round them, then you can adjust the interval to control which of the category labels are displayed, but it wont pick values that fall between your timestamps to make your interval an evenly rounded datetime value.
If you want some of those features you might have to start looking into the CategoryDateTimeXAxis which generates labels based on intervals in the datetime space, rather than intervals on the category index. As a result, items that have a larger delta in their time value will also look further apart than items with a smaller time delta.
The appropriate axis to choose will depend largely on what your data looks like, and what the requirements are for how the series and axes are displayed. The CategoryDateTimeXAxis was not added until later in the development cycle, so you may not have had a chance to experiment with it during the CTP.
Based on this I believe I will have to go with the CategoryDateTimeXAxis. However, my initial attemp at using it does not display the line (none of the y value points are visible). The xaxis datetimes are displayed and as new values come in they are moving but no points are visible.
Essentially I just changed my type from CategoryXAxis to CategoryDateTimeXAxis, set the Displaytype and DateTimeMemberPath and removed the interval property. Is there more to it than that?
Mike,
I'm not sure if even the CategoryDateTimeXAxis will help keep your label intervals rounded if you are removing and adding the points in real time. You can set an interval, but if x axis span isn't evenly divisible by the interval then your labels will fall on non even values. I believe there may be some smart snapping features in our backlog for the CategoryDateTimeXAxis, but you may want to make a feature request also. Its important to note that the CategoryDateTimeXAxis does not let you manually set the minimum and maximum values currently, so you couldn't keep those updated along with the data to ensure the span was evenly divisible.
From my testing, there may be an floating point arithmetic issue with the CategoryDateTimeXAxis currently if your first and last values are very close together in terms of ticks, as may be your case. If you can send us a sample of how you have it configured, we can identify any potential bugs and try and assert that the scenario works for the first service release of the chart, or earlier if it is only a configuration issue.
Graham,
I have created a messy sample to demonstrate what I am trying to do but using the CategoryXAxis. If I simple change the x axis to CategoryDateTimeAxis (and add the DateTimeMemberPath and DisplayType) then nothing works any longer. Queuing/Dequeuing seem to always be invalid index (although that seems to be ok in my full app), the HoveredCategoryItems behavior does not work and nothing shows up on the chart. Can you tell me where I should dent the sample as I cannot attach it here?
Mike
The above bug is resolved, you must be encountering a different issue. Could you provide a sample that illustrates your problem?
Is there a target date for when this bug will be fixed? We're also running into the same issue with the CategoryDateTimeXAxis where the X label no longer shows up when we set DisplayType="Discrete". Already downloaded & install the latest service release for 10.3 (NetAdvantage_WPF_20103.2116_SR.exe) but the labels are still missing.
Sorry for the late response, I've been out of the office. Here is a workaround you can use to make the axis function correctly with short time intervals, until the fix is released.The Xaml:
<UserControl.Resources> <local:TimeTranslator x:Key="translator" /> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <Grid.RowDefinitions> <RowDefinition /> </Grid.RowDefinitions> <ig:XamDataChart Name="xamDataChart1" VerticalZoomable="True" HorizontalZoomable="True" > <ig:XamDataChart.Axes> <ig:CategoryDateTimeXAxis x:Name="xAxis" ItemsSource="{Binding}" DateTimeMemberPath="Date"> <ig:CategoryDateTimeXAxis.Label> <DataTemplate> <TextBlock Text="{Binding Item.Date, Converter={StaticResource translator}}" /> </DataTemplate> </ig:CategoryDateTimeXAxis.Label> </ig:CategoryDateTimeXAxis> <ig:NumericYAxis x:Name="yAxis" /> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:LineSeries x:Name="testLine" ItemsSource="{Binding}" XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis}" ValueMemberPath="Value" /> </ig:XamDataChart.Series> </ig:XamDataChart> </Grid>
And the code behind:
public partial class MainPage : UserControl { private DispatcherTimer _timer = new DispatcherTimer(); public MainPage() { InitializeComponent(); DataContext = new TestData(); _timer.Interval = new TimeSpan(0,0,0,0,250); _timer.Tick += timer_Tick; _timer.Start(); } void timer_Tick(object sender, EventArgs e) { ((TestData)DataContext).AddPoint(); } } public class TestDataItem { public DateTime Date { get; set; } public double Value { get; set; } } public class TimeTranslator : IValueConverter { private static DateTime _progStartTime = DateTime.Now; public static DateTime Translate(DateTime from) { return new DateTime(((from - _progStartTime).Ticks * 170000) + _progStartTime.Ticks); } public static DateTime UnTranslate(DateTime from) { return new DateTime(((from - _progStartTime).Ticks / 170000) + _progStartTime.Ticks); } public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if ((targetType == typeof(DateTime) || (targetType == typeof(string))) && value is DateTime) { return UnTranslate((DateTime)value); } return DateTime.MinValue; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } } public class TestData : ObservableCollection<TestDataItem> { public TestData() { for (int i = 0; i < 100; i++) { AddPoint(); } } private static Random rand = new Random(); int _i; double _curr; public void AddPoint() { if (rand.NextDouble() > .5) { _curr += rand.NextDouble(); } else { _curr -= rand.NextDouble(); } Add( new TestDataItem() { Date = TimeTranslator.Translate(DateTime.Now), Value = _curr }); _i++; } }
-Graham
I'll see if I can come up with some sort of work around you can use in the meantime. I've fixed this bug and marked it resolved but it has not gone through quality assurance yet, The changes should be available in the next service release for the product. You should be able to contact support and product management and see if you might be able to get some early builds to help you out, and this would assist us in ensuring your other scenarios are well covered.
I have been trying to work around the CategoryDateTimeXAxis problem by increasing the interval time between points but so far no interval seems to make any difference. Can you help me get around this issue? What is the potential turn around time for bugs? We are in process of purchasing this package with support. Will that help get updated code with some of these bugs fixed?