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
15
How to dynamically create a stacked column series with MVVM Binding
posted

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

Parents
No Data
Reply
  • 30490
    Offline posted

    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

Children