Hi,
I am trying to create a dynamic stacked column series that binds to the data in view model.
Here is the sample of data I have
var ChartData = new ObservableCollection<CityData>();
public class CityData
{
string CityName;
ObservableCollection<CityInfo> Info;
}
public class CityInfo
string BuildingType
int BuildingCount
I am trying to create a stacked column series with City names on X axis and columns with multiple stacked fragmented series by Building Type and Count
Hello Priyanka,
I have been investigating into the behavior you are looking to achieve in this case, and I would like you to take a look at the sample project I am attaching.
The sample project’s XamDataChart is using the “UpdatedViewModel,” as the “ViewModel” was used for an attempt to use your data structure for this, but this will not work. Your data structure appears hierarchical in nature, and there is no easy way for the StackedColumnSeries to work with this.
Instead, I would suggest that you format your data structure into a DataTable. Your columns in the DataTable in this case would be CityName and then as many BuildingTypes that you need. The values of the rows would then be the name of the city and the value of BuildingCount for the BuildingType. This would allow you to dynamically add as many BuildingTypes that you would need as well as many cities that you would need to plot. The sample project I am attaching does this and allows you to add new cities and building types dynamically.
I hope this helps you. Please let me know if you have any other questions or concerns on this matter.
XamDataChartDynamicStackedSeries.zip
Hi Andrew,
The solution is great, but I was wondering if I can auto generated stackedfragmentseries and update the chart when the data in the backend updates.
How can I modify the code to auto-generate StackedFragmentSeries and use DataTable with hierarchial data
I would like you to take a look at the modified sample project I am attaching in this case.
In order to utilize the “auto-generate” functionality of the StackedColumnSeries, you will need to utilize a different type of data source in this case, called a GroupBy. This is required in order to use the StackedColumnSeries with auto-generate.
The StackedColumnSeries will also not work with auto-generate if you are using hierarchical data or a DataTable, and being that you are looking to have backend updates happening easily, I have made some modifications to the data structure in this case as well. The sample project is back to utilizing an ObservableCollection in a group-by structure that is feeding the GroupBy data source, which will make updates on the back-end simpler as long as you are implementing the INotifyPropertyChanged interface on the underlying data item.
I am attaching the sample project here. Please let me know if you have any other questions or concerns on this matter.
7802.XamDataChartDynamicStackedSeries.zip
Currently the data structure I like to use looks like this -
DataStructure - ObservableCollection<DataType1>
DataType1 = {DataType2, ObservableCollection<DataType3>}
DataType2 = {string21, string22}
DataType3 = {string31, string32, int33}
The data I am trying to plot on my stacked column series is (string21) on X-axis
For each stacked column, I am trying to plot string31 and int33.
Using the above data structure, how can I set GroupBy MemberPaths to properties that are nested inside my data structure so I can plot them as desired.