I have a service that will return 0 or more sets of data. The data structure looks like this:
public class ReportData
{
public List<SeriesSet> SeriesSet {get;set;}
}
public class SeriesSet
{
public DateTime ItemDate {get;set;}
public List<SeriesItem> SeriesItem {get;set;}
}
public class SeriesItem
{
public string ItemType {get;set;}
public double ItemValue {get;set;}
}
My Service will return ReportData which contains a List of SeriesSets. SeriesSet data contains a List of SeriesItems. Each SeriesItem in SeriesSet has to be a data item in a corresponding series in my chart (i.e. a separate line or bar) for that SeriesSet’s particular date. I want to dynamically create the series in the chart based on what comes back from the service.
I think I need to first identify the different ItemTypes that are returned then based on that create the series mappings.
One of the problems I’m running into is the data comes from a web service which is asynchronous. How do I create series mappings with proper bindings in my view when the data comes into my viewmodel?
From the way I’ve been creating charts it almost seems like I need to have my series mappings defined before I get the data from my view model?
Any pointers?
I did something similar to this recently. My SeriesMappings’ ItemSources were bound, though the SeriesMappings themselves and the bindings were created in code-behind.
I had my view model fire an event when its data was all loaded. The view handled the event and added new SeriesMapping objects to the chart. Here’s some of the code for creating the SeriesMapping objects.
UPDATE:
In order for the view model to communicate data and mapping information to the view, perhaps you could do something like this.