I am converting my Silverlight project to WPF and trying to follow the MVVM pattern. My current Silverlight solution is each time a "channel" is selected by the user, in the code behind, I manually create an x and y axis, series, link them together and then add them all to the XamDataChart that I defined in the XAML.
I am now trying to use data binding as much as possible but I am not sure if it can be accomplished with data binding alone. Each "channel" needs to have an individual y-axis since the ranges will be different but they can all share the same x-axis (or those can be independent as well, either way will work for my purposes). Also, I had originally used CategoryDateTimeXAxis but now I am updating the chart every second so the interval will always be 1 second and I can therefore use the NumbericXAxis which gives me more control over the label formatting anyway (at least in Silverlight it did). How can I add a single pre defined NumericXAxis in the XAML but them bind all y-axes and series to an ObservableCollection that changes when a user selects or deselects a "channel" or should I even do that?
Suggestions? Do I need to describe what my goals are a little better?
Hello Mike,
Thank you for your post. I have been looking into the functionality that you are trying to achieve and since the Series collection and the Axes collection of the XamDataChart are not bind-able. I have created a sample application for you that demonstrates how you can dynamically add and remove Series and Axis from the XamDataChart, without using code behind. In the sample application I have added a ListBox with multiple selection and a XamDataChart with one NumericXAxis. I have bound the XamDataChart’s Tag property to the SelectedItems of the ListBox and to the XamDataChart itself using MultiBinding. In the Converter of the MultiBinding I am adding a series for each item in the SelecteItems collection. I am binding the DataContext of each series to the corresponding item of the selected items of the ListBox and also binding the ItemSource and set the XAxis of each series to use the one added in the XamDataChart in xaml. When a series exist in the Series collection of the chart and not in the selected items, I am setting the Visibility of the series and its YAxis to Collapsed in order to hide it and by doing so the series are added only once and not re-added each time.
Please let me know if this approach suits your scenario and if you need any further assistance on the matter.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
Hi,
I tried to modify this program sample attached a bit to adapt to Line series and attaching the sample as well.
I am not able to display X axis in the sample . Not sure what I am missing here. Could you please assist?
Thanks
Sunil
Did anyone get a chance to look into this?
thanks
Hello Sunil,
Thank you for your post. I have been looking into it and the sample you have provided and I modified the sample, so now it works as you want. Basically I changed the Label and the Binding of the CategoryXAXis.
Hope this helps you.
Thanks it worked ...:-)
Hi ,
I have found this thread very useful and simple to use. Just wanted to find out how would I be able to set the tooltip to display the datapoint details?
-Sunitha
Hello Sunitha,
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.
I have managed to resolve this by creating the tool tip programmatically and assigning it to the series.
thanks,
Sunitha