hi,
I'm trying to dynamically creatDynamically StackedFragmentSeries of a StackedColumnSeries. For some reason, at the run time, the execution stuck after setting ItemSources for a GroupBy object.
---XAMl---
<Page x:Class="DynamicStackColumnCharts.Page1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:igChart="http://schemas.infragistics.com/xaml" xmlns:local="clr-namespace:DynamicStackColumnCharts" mc:Ignorable="d" Loaded="Page_Loaded" d:DesignHeight="300" d:DesignWidth="300" Title="Page1"> <Page.Resources> </Page.Resources> <Grid> <igChart:XamDataChart x:Name="theChart"> </igChart:XamDataChart>
</Grid></Page>
-----code-----------------
using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using System.Collections.ObjectModel;using Infragistics.Controls.Charts;using Infragistics;
namespace DynamicStackColumnCharts{ /// <summary> /// Interaction logic for Page1.xaml /// </summary> public partial class Page1 : Page { GroupBy gb ; public Page1() { InitializeComponent(); }
private void stack_SeriesCreated(object sender, Infragistics.Controls.Charts.StackedSeriesCreatedEventArgs e) { StackedFragmentSeries series = (StackedFragmentSeries)sender;
if (series != null) { series.Title = series.ValueMemberPath.Replace("_Count", string.Empty); } }
private void Page_Loaded(object sender, RoutedEventArgs e) {
gb= new GroupBy(); gb.GroupMemberPath = "Date"; gb.KeyMemberPath = "Installation"; gb.ValueMemberPath = "Emission"; ObservableCollection<InstalationEmissionDateInformation> temp = TestEmissionsCollection.GetItemSource(); gb.ItemsSource = temp;
NumericYAxis yAxis = new NumericYAxis(); CategoryXAxis xAxis = new CategoryXAxis(); xAxis.ItemsSource = gb; //xAxis.Label = "{Country}"; this.theChart.Axes.Add(xAxis); this.theChart.Axes.Add(yAxis);
StackedColumnSeries series = new StackedColumnSeries(); series.XAxis = xAxis; series.YAxis = yAxis; series.ItemsSource = gb; series.AutoGenerateSeries = true; theChart.Series.Add(series);
}
public class TestEmissionsCollection {
public static ObservableCollection<InstalationEmissionDateInformation> GetItemSource() { ObservableCollection<InstalationEmissionDateInformation> retVal = new ObservableCollection<InstalationEmissionDateInformation>(); retVal.Add(new InstalationEmissionDateInformation("A", 5, "1/1/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("B", 2, "1/1/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("C", 7, "1/1/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("A", 6, "1/2/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("B", 3, "1/2/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("C", 8, "1/2/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("A", 6, "1/3/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("B", 3, "1/3/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("C", 6, "1/3/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("A", 4, "1/4/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("B", 3, "1/4/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("C", 7, "1/4/2012", 1)); return retVal; }
public TestEmissionsCollection() { } }
public class InstalationEmissionDateInformation { public string Installation { get; set; } public Decimal Emission { get; set; } public string Date { get; set; } public Decimal Assignation { get; set; }
public InstalationEmissionDateInformation( string installation, Decimal emission, string date, Decimal assignation) { Installation = installation; Emission = emission; Date = date; Assignation = assignation; } }
Hello Lily,
Thank you for your reply. I am very glad my suggestion helped solving your issue. If you need any further assistance please do not hesitate to ask.
Sincerely,
Krasimir
Developer Support Engineer
Infragistics
www.infragistics.com/support
thanks, it worked!
I am just checking if you require any further assistance on the matter.
Thank you for your post. I have been looking into it and when you are using a GroupBy, the DataContext of that for the labels is a dynamically generated object. This object contains properties for each object in the group and also a Key property that represents the value of the current group. You can use the Key property for the Label property of the CategoryXAxis. Here is the properties on the dynamic object, which comes as a DataContext of the labels of the x axis:
You can use a DataTempalte with a TextBlock and bind the Text to the key or one of the other properties and also you can set the Label property to “{<PropertyName>}”.Here is an example for that:
Xaml:
<Page.Resources> <DataTemplate x:Key="labels"> <TextBlock Text="{Binding Item.Key}" Loaded="TextBlock_Loaded"/> </DataTemplate> </Page.Resources>
C#:
.... CategoryXAxis xAxis = new CategoryXAxis(); xAxis.ItemsSource = gb; //Using DataTempalte for the labels //xAxis.Label = Resources["labels"] as DataTemplate; xAxis.Label = "{Key}"; ....
I have created a sample application that demonstrates how you can implement the above mentioned functionality.
Please let me know if you need any further assistance on the matter.
this is XBAP application, after i set the security to full trust. GroupBy object itemsource is able to set.
How to display Label for CategoryXAxis?