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
215
Chart with multiple series from ObservableCollection<ObservableCollection<PriceDataHistory>>
posted

I'm still new to WPF, Data Binding, Infragistics, and reallly GUI Windows Development... Sometimes I find working with the XamDataChart a little confusing for displaying complex objects, but I think it falls down to my understanding of how the XAML Binding Works with the charting package.

I have

public class PriceDataHistory ObservableCollection<Price>

Price is a custom object that looks like:

    public class Price
    {
        public string Country { getset; }
        public string LocationCode { getset; }
        public DateTime Date { getset; }
        public double Price { getset; }
    }

I have many data points in the Observable collection and I would like to display them grouped by LocationCode.

So, for example If I have three different locations I would like to display 3 series on the chart.

   
   public class PriceDataHistory ObservableCollection<Price>
    {         public PriceDataHistory()         {             for (int i = 0; i < _priceDates.Count; i++)             {                 this.Add(new Price                 {                     LocationCode = _location[0],                     Date = DateTime.Parse(_priceDates[i]),                     Price = float.Parse(_price0[i])                 });                 this.Add(new Price                 {                     LocationCode = _location[1],                     Date = DateTime.Parse(_priceDates[i]),                     Price = float.Parse(_price1[i])                 });                 this.Add(new Price                 {                     LocationCode = _location[2],                     Date = DateTime.Parse(_priceDates[i]),                     Price = float.Parse(_price2[i])                 });             }         }
        ///... not necessary for example
    }

In the example data they all have the same number of points

and they all have the same Date.

In the future I will not know how many different

LocationCodes there will be, because I'm using test

data right now so it is static.

 

Is what I want even possible? How should I go about

binding to my object in XAML?

Parents
  • 30945
    Offline posted

    Hello,

     

    Thank you for your post. I have been reading through it and if I understand correctly you have a ObservableColleciton of Price objects and you wish to group your collection by the LocationCode property and create a series for each group. If my assumption is correct, I can suggest creating a method to which you can pass the PriceDataHistory and the XamDataChart. In this method using a linq query you can group the PriceDataHistory by the LocationCode property into a new collection of objects that will contains the LocationCode and a collection of the data for the given location. By looking though this collection you can create a new series for each LocationCode  and add it to the XamDataChart. I have created a sample application for you, which demonstrates the approach that I have described.

     

    Please let me know if you need any further assistance on the matter.

     

    Sincerely,

    Krasimir

    Developer Support Engineer

    Infragistics

    www.infragistics.com/support

    CollectionGroupingIntoSeries.zip
Reply Children