Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
3590
How to bind multiple collections to single XamDataChart?
posted

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?

Parents
  • 30945
    Verified Answer
    Offline posted

    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

    SeriesAddingWithCommand.zip
Reply Children