3

I am trying to generate a splined chart which will have multiple series each with a number of points. I have done something in Excel which looks like this

Excel version of chart

Except I will have more like seven ellipses within each other.

I have selected the WPF Toolkit to use as it is free, and I have generated all of the points, I have put them in the following structure.

List<List<KeyValuePair<double, double>>>

Where the outer list is the list of series and the inner list is the list of points in that series.

I do not see a item source to bind to to generate the list of series, how would I go about binding to this?

Edit

I have backed off on what I want to do, I had wanted to have a dynamic binding to a list of lists where the user can define any gradient curves they would like, each one with a collection of points.

Now what I have done is made a specific set of curves (about 7) and filled them with all the points, letting the user choose from that defined list.

Here is the XAML I wrote for this,

<chartingToolkit:Chart Title="Compressor Map">
                <chartingToolkit:LineSeries  DependentValuePath="Value"
                                             IndependentValuePath="Key"
                                             ItemsSource="{Binding Path=Points[0]}"
                                             IsSelectionEnabled="True" />

                <chartingToolkit:LineSeries  DependentValuePath="Value"
                                             IndependentValuePath="Key"
                                             ItemsSource="{Binding Path=Points[1]}"
                                             IsSelectionEnabled="True" />
            </chartingToolkit:Chart>

Where I am planning on toggling visibility based on a set of choices. This however does not work, it gives the following error,

System.Windows.Data Error: 17 : Cannot get 'Item[]' value (type 'List1') from 'Points' (type 'List1'). BindingExpression:Path=Points[0]; DataItem='ChartViewModel' (HashCode=4925117); target element is 'LineSeries' (Name=''); target property is 'ItemsSource' (type 'IEnumerable') ArgumentOutOfRangeException:'System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values. Parameter name: index'

I would rather not have to make seven different properties, one for each level set. First I feel like that is brute force, also I have an inner loop that fills the points for each level and writing the entire loop out would be horrific.

Thank you for the help.

kleineg
  • 462
  • 1
  • 6
  • 18
  • Could you please post your xaml code? and codebehind/vm for the given dict? BTW you cannot bind to dictionaries. – Stígandr Aug 24 '14 at 00:35
  • @Stian. Made an edit to show where my progress is up to now. – kleineg Aug 24 '14 at 14:36
  • 1
    You can do what you wanted to do. I have done it by inheriting from Chart and adding a dependency property called SeriesSource. My property changed method then loads the set template and does a foreach through the SeriesSource adding an instance of the template for each subcollection of points. Here is a link to a SilverLight version using an Attached Property to achieve this http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/351/Silverlight-Charts-Binding-multiple-Series.aspx. Shouldn't be too hard to convert this to WPF if anything even needs changing at all. – Lee O. Aug 25 '14 at 04:14
  • @LeeO. Thank you, that helped a lot. Put that exactly in an answer and I will accept. – kleineg Aug 26 '14 at 12:18

1 Answers1

1

You have a few options for achieving your desired results. I inherited from Chart and created a MultiChart by adding a couple of Dependency Properties. One for my source of items and one for the template to use. In the property changed callback for the source, you foreach through the SeriesSource adding an instance of the template for each subcollection of points.

Here is a link to a SilverLight version that is using an Attached Property to achieve this. It should be fairly straightforward to convert this to WPF if it even needs any changes at all.

http://jmorrill.hjtcentral.com/Home/tabid/428/EntryId/351/Silverlight-Charts-Binding-multiple-Series.aspx

Lee O.
  • 3,212
  • 2
  • 26
  • 36