I am looking to a solution to this post that uses CategoryDateTimeXAxis:
http://es.infragistics.com/community/forums/t/52624.aspx
The example works but, unfortunately, CategoryXAxis requires all series on the chart to have all x-values "aligned", so if I have two series that do not have completely matching times for the x-axis data, the second series will not be rendered (see http://es.infragistics.com/community/forums/p/38082/220246.aspx). I tried to drop in a CategoryDateTimeXAxis in the example since it allows "non-aligned" x-values but that doesn't work - for example, simply changing this:
<igChart:CategoryXAxis x:Name="xAxis" ItemsSource="{StaticResource data}">
to this:
<igChart:CategoryDateTimeXAxis x:Name="xAxis" ItemsSource="{StaticResource data}" DateTimeMemberPath="Date">
does not work. Any suggestions on how to alter the referred posts' example for this type of X-Axis?
Hello Gary,
Thank you for your post!
I have been investigating into this issue, and it appears that with the current bindings on the DateLabel object that now represents the CategoryDateTimeXAxis's Label, you should be getting a large amount of binding expression errors in the Visual Studio output window. This is being caused due to the ElementName binding to find the Chart property of the DateLabel object. To get around this, rather than using an ElementName binding, you can use the following: {Binding Axis.Chart}.
The above fixes the binding errors, but the labels still do not render. This appears to be a timing issue with the XamDataChart and the axis being created, but I am not entirely sure as of yet. One thing that is rather disturbing about this is that the GetDateLabels() method on the DateLabel class is now returning the correct number of DateLabel objects, but each of their Date properties is set to 1/1/0001. This is also causing the AxisScale to always be returned as "Minutes" as well, which isn't correct. At the start, it should be "Years".
I am going to continue to investigate this to see what is going on here. To use this with the CategoryDateTimeXAxis, it currently appears that a different custom object may need to be constructed. I will update this forum thread again when I have more information for you.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Thanks for looking at this. If you can post a working example when ready, that will be most helpful.
Thanks!
Thanks Andrew, the charting app I am working on dynamically creates most of the chart components, including the axes, in the code behind, so I had some initial issues using a dynamically created CategoryDateTimeXAxis, but I was able to switch this to be static and things are now operating as expected.
Hi Andrew, one thing did pop up here: When you zoom in to a "hours level", you only see 12:00 as labels. This seems to be due to the GetDateLabels() call not providing dates that are more precise than a day. Not sure how to get this to provide tickmarks showing correct hours, min, etc. when zooming into that level as it isn't clear to me what is providing the actual date values for each tick. Seems like the Axis is providing these values.
Your version works but my attached version using a code behind does not.
I have been investigating into this, and I have been able to reproduce this issue that you are seeing. It appears that this issue is mainly coming from the setting of the Date property on the DateLabel class, as when it is set in the OnDateChanged method, it appears that this property is set to the correct day, month, and year, but the time is set to 12:00AM. In other words, it appears that the binding is not respecting the time of the Date when it is bound in this case.
To work around this, I would recommend a modification to the Loaded event of the DateLabel, which was implemented earlier in this discussion. In this Loaded event, you can cast the sender of the event to a DateLabel object and get its DataContext, which in this case will be an AxisItemDataContext element. This AxisItemDataContext has an Item property, which will be the correct date with the correct time. I would recommend that you retrieve this date, and then set this.Date (the DateLabel's Date property) to that DateTime object. Then you can make the call to Update(), since the Update() method uses this Date property.
I have attached a modified version of the sample project you sent to demonstrate the above. I hope this helps you.
Thanks Andrew, your suggestion works. Based on your investigation, I took a look at the Axis Label data template that contains the DateLabel binding. I realized that is the point where the Date is being truncated to the whole day (as you indicated) and made this change:
<Window.Resources> <DataTemplate x:Key="labelTemplate"> <local:DateLabel Date="{Binding Item.Date}" Chart="{Binding Axis.Chart}"/> </DataTemplate> </Window.Resources>
to:
<Window.Resources> <DataTemplate x:Key="labelTemplate"> <local:DateLabel Date="{Binding Item}" Chart="{Binding Axis.Chart}"/> </DataTemplate> </Window.Resources>
Since "Item" is the actual DateTime value, when I specify "Item.Date", that truncates the date to the whole day and that is the value that gets set on the DateLabel object. Removing that part of the binding (effectively binding to the wrong property) solves my issue as well. Thanks for the quick analysis!
Thank you for your feedback. I am glad I was able to assist you on this matter.