Hello,
I have a xamdatachart that needs to show both Line Series (Numeric y-Axis and DateTime on X-axis) and StepLineSeries (Strings on Y-Axis and DateTime on X-axis).
Line series is fine, but with StepLineSeries I have some problems.
1.) Right now I am mapping string values to some numeric values like 0,1,2 ... etc. to plot it againts Datetime x-axis. Is this the only way or can I bind the string values directly to y axis keeping datetime x-axis as it is?2.) If I use the numeric y axis, to support both series on the same chart (using above mentioned way), I am having trouble with y-axis labels. How to bind the y-axis label with the 'Label' property (string type) that I have in the model class the series is binded with the collection of?
PS: I know the Y2 axis as well and that too needs to be handled the same way Y1 axis will be.
Please answer ASAP. Thanks in advance.
Hello Rob,
Thank you for your post.
I have been investigating into this issue that you are having, and to my knowledge, I don't believe you can currently bind the Label property of the Numeric axes to a string value. They expect numeric values. However, there is still a way that you can achieve your requirement by continuing with the string value mapping.
The axes in the XamDataChart have an event named FormatLabel, and this fires when the XamDataChart loads and the labels for that particular axis are created. This event will be fired for each label that is created for that particular axis, and you can get what the label normally would be from the parameters of the event handler. The event handler for this event is not a void, though, as it expects a string to be returned to be used for the label.
With the above in mind, I would recommend that you continue with the string mapping and query the collection that you have bound to the XamDataChart based on the value that would normally exist for your particular label. This will allow you to get the string that you have mapped to that particular number that would normally be displayed as the label for the YAxis and return the string representation of it. That string will then be shown in its place. This should work for usage of multiple y axes in for multiple series as well, as I have demonstrated in the attached sample project.
I hope this helps 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 your quick response.
I am using Infragistics v11.2 at present. Format Label isn't there in it. Is there any way to do this in v11.2?
In the Infragistics 11.2 version of the XamDataChart, creating a custom, mapped label is not as simple as handling an event. Instead, I would recommend creating a custom object that derives from ContentControl. In the constructor of this custom object, you can place a TextBlock or other element that you wish to make up the label into the Content property of your custom object.
I would recommend adding two dependency properties to this custom label object. One to keep track of the XamDataChart, and the other to keep track of the Item that the label would have displayed normally. When these properties change, you can make a call to another method that will update the element that you placed in the Content property as mentioned above by hooking into a property changed callback for your dependency properties and casting the DependencyObject of this property changed callback to your custom axis label object and then calling a method that you set up on it.
Now, the Label property on the axes of the XamDataChart does not necessarily have to be a string. You can also create a DataTemplate for it. I would recommend that you do just this and place your custom label object in this data template. You can set the Chart and the Item by binding them to {Binding Axis.Chart} and {Binding Item} respectively, as the data context of this item will have access to these properties. Then, in the method called by the property changed callbacks as mentioned above, you can obtain your collection from the data context of the XamDataChart, and query your collection using the Item dependency property like before. Then, set the Content object to the desired value.
I have attached a modified version of the original sample project I had sent you to demonstrate the above.
The code-base of 15.2 and 15.1 with respect to the XamDataChart is largely the same, but there were a few things added. You can see the features that were added here: http://help.infragistics.com/doc/WPF/2015.2/CLR4.0/?page=Whats_New_in_2015_Volume_2.html. Also, the 15.2 product is still very young in its product lifecycle with much development still to come for it, whereas 15.1 is a little bit older and has a little bit less development scheduled for it. For these reasons, I would recommend upgrading to 15.2 over 15.1 at the moment.
Regarding the custom tooltip, you can set the Tooltip property on your series in your XamDataChart to a new ContentControl and set the content of that ContentControl to be what you would like to show on hover of the markers. This tooltip's data context will be that of an Infragistics.Controls.Charts.DataContext item, which will have access to the Series and the data item that is used. So, for example, if you bind a TextBlock's Text property to Series.Title or Item.PropertyNameOnDataItem, you can show your data item properties or the title of the series in the tooltip on the markers of your series.
On terms of modifying the sample project to get the string label from the data context of the NumericYAxis label rather than a list from the ViewModel, I have been speaking with my colleagues about doing this, and unfortunately, every path to doing this will lead to essentially the same thing that is done in the UpdateLabel method of the CustomLabel class in the sample I had sent you. The numeric axes in the XamDataChart don't really have any concept of a "data item." They work directly with the series itself and display the parts of the series that correspond to certain values as designated by the ValueMemberPath of the series. For you to get the data items directly from the data context of the labels, this would require you to correlate your data source with the label somehow, which would almost certainly involve bringing in the ViewModel and the collections contained in it, which is what is currently being done in the sample.
I have attached a modified version of the sample project that I had sent you to demonstrate the custom tooltips on the markers of the StepLineSeries. I hope this helps.
Please let me know if you have any other questions or concerns on this matter.
Hi Andrew,
I am planning to upgrade to v15.1 or v15.2. Which one do you prefer?
Can you modify the sample to get the string label from the datacontext and not any list from the viewmodel? I want this to be efficient so I am avoiding mapping with multiple lists approach.
Is it possible to set a customized tooltip on marker? As there are multiple series on my chart, I want to add the series name as well in the existing marker tooltips.
Thanks for the help Andrew!
In the 11.2 version of the XamDataChart, I don't believe there really is a way of directly getting the SampleData object that exists for a particular category label. In that version, the data context of the labels of the XamDataChart exposes two properties: Item and Axis. The Axis property returns the axis that the particular label belongs to, and the Item property returns the value that it would normally display. I suppose if you didn't want to use the ViewModel in your custom label object, you could pass in the Axis as another dependency property and loop through its ItemsSource, but I believe each path will lead to the need to query a collection to get your data item.
Thanks for the help Andrew.
I saw this method UpdateLabel():
public void UpdateLabel() { if (Chart != null && Item != null) { int i = int.Parse(Item.ToString()); ViewModel VM = Chart.DataContext as ViewModel;
SampleData SD = VM.Data.Where(sd => sd.Value == i).FirstOrDefault();
if (SD != null) { textBlock.Text = SD.YAxisLabel; } } }
and I was wondering if we can get the item (SampleData object) directly instead of traversing through ViewModel approach? That would be more clean and will fit easily as I personally dont feel like storing items list just for this thing, when there any many charts and many series on each chart.
Do you think there is any solution to this?
Thanks & Regards,
Rob