How can I dynamically create a stacked column series? I'm setting AutoGenerateSeries="true", but unable to find where I can define the KeyMemberPath or ValueMemberPath. Also, I don't need to use the ig:GroupBy resource because we already calculate the totals in SQL before it hits the app. Is there another resource setting I can create to assign these objects appropriately?
Hello PMac,
The reason that the GroupBy is never "getting" your ObservableCollection is because its ItemsSource cannot be directly bound. The GroupBy object derives directly from DependencyObject, and so is not a FrameworkElement. This essentially means that it does not expose a DataContext property, which is necessary for direct binding.
I would recommend that you use a StaticResource binding or perhaps create the GroupBy programmatically. It also may be considerable to create a GroupBy property in your ViewModel, which you can then populate with your ObservableCollection there. At that point, you could bind your CategoryXAxis and StackedColumnSeries ItemsSource properties to your underlying GroupBy ViewModel property.
Please let me know if you have any other questions or concerns on this matter.
Sincerely,AndrewAssociate Developer
Having trouble calling the ObservableCollection that contains the data points. For some reason the "get" is never called, even after the "set" along with my OnPropertyChanged method (Data is changed when my "search" button is clicked). All other charts are working normally, but using the GroupBy fails to retrieve the observable collection for this dataset. Any thoughts?
Here is my XAML code...
<ig:XamDataChart Height="325" Title="Total Reports"> <ig:XamDataChart.Resources> <ig:GroupBy x:Key="GroupedTotalReport" ItemsSource="{Binding TotalReportsData}" GroupMemberPath="month_year" KeyMemberPath="task_name" ValueMemberPath="num_records" /> </ig:XamDataChart.Resources> <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="StackedColumnXAxis" ItemsSource="{StaticResource GroupedTotalReport}" Label="{}{Key}" /> <ig:NumericYAxis x:Name="StackedColumnYAxis"/> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:StackedColumnSeries x:Name="TotalReportStack" ItemsSource="{StaticResource GroupedTotalReport}" XAxis="{Binding ElementName=StackedColumnXAxis}" YAxis="{Binding ElementName=StackedColumnYAxis}" AutoGenerateSeries="True" > </ig:StackedColumnSeries> </ig:XamDataChart.Series> </ig:XamDataChart>
Thank you for your update.
From the descriptions of your scenario in this case, I agree that using the GroupBy resource rather than the SQL group-by would be your best option in this case.
Okay great, thank you for the reply. I'm trying to stick with the MVVM architecture, so the latter option may be tough to plug. I'll unhinge the groupby in SQL and use the groupby resource to construct the member-value objects. Was hoping for another option but this should work. Thanks!
Auto-generation in the StackedColumnSeries requires the usage of a GroupBy ItemsSource, as the StackedColumnSeries does not have an inbuilt KeyMemberPath or ValueMemberPath.
Instead, when using a traditional list of objects, you are expected to populate the StackedColumnSeries.Series collection with StackedFragmentSeries objects. These StackedFragmentSeries objects have a ValueMemberPath property that you can set corresponding to the underlying data items that exist in the collection used for your ItemsSource. The "Key" in this case will correspond to the category which is bound to your CategoryXAxis' Label property. For example, if you had a Label setting in your CategoryXAxis of "{}{Country}," the key would be the underlying Country property on the data items that are bound to the ItemsSource of your chart.
So, in order to dynamically create a StackedColumnSeries, I would recommend looping through each of the properties that you are looking to create a column fragment for, create a StackedFragmentSeries for each, and add it to the StackedColumnSeries.Series collection.
I hope this helps. Please let me know if you have any other questions or concerns on this matter.