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 { get; set; } public string LocationCode { get; set; } public DateTime Date { get; set; } public double Price { get; set; } }
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?
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?
also see: http://community.infragistics.com/forums/p/50183/264009.aspx#264009
But note the wpf corrections in a further reply.
-Graham
This looks like what I was going for, but I was hoping to have a solution where the binding was done in XAML.
I can complete my tasks using this programmed method, is it possible to create a converter that would do this?
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