Could anyone help how to add the Stacked area series dynamically?
following code sample will create 3 stacked area series. I need to append additional series in button click event.
Could any one help?
xaml:
<Window x:Class="InfragisticStackedChart.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ig="clr-namespace:Infragistics.Controls.Charts;assembly=InfragisticsWPF4.Controls.Charts.XamDataChart.v11.2" Title="MainWindow" Height="350" Width="525" Loaded="MainWindow_OnLoaded"> <Grid> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <ig:XamDataChart Grid.Row="1" x:Name="theChart" Legend="{Binding ElementName=xmLegend}" /> <ig:Legend Grid.Row="0" x:Name="xmLegend" Background="White" Orientation="Horizontal" /> </Grid> </Window>
Code:
namespace InfragisticStackedChart { using System.Collections.ObjectModel; using Infragistics; using Infragistics.Controls.Charts; /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void MainWindow_OnLoaded(object sender, RoutedEventArgs e) { GroupBy gb = new GroupBy(); gb.GroupMemberPath = "Date"; gb.KeyMemberPath = "Installation"; gb.ValueMemberPath = "Emission"; ObservableCollection<InstalationEmissionDateInformation> temp = TestEmissionsCollection.GetItemSource(); gb.ItemsSource = temp; Infragistics.Controls.Charts.NumericYAxis yAxis = new NumericYAxis(); CategoryXAxis xAxis = new CategoryXAxis(); xAxis.ItemsSource = gb; // xAxis.Label = Resources["labels"] as DataTemplate; xAxis.Label = "{Key}"; this.theChart.Axes.Add(xAxis); this.theChart.Axes.Add(yAxis); StackedAreaSeries series = new StackedAreaSeries(); 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)); retVal.Add(new InstalationEmissionDateInformation("D", 7, "1/1/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("D", 8, "1/2/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("D", 6, "1/3/2012", 1)); retVal.Add(new InstalationEmissionDateInformation("D", 7, "1/4/2012", 1)); //retVal.Add(new InstalationEmissionDateInformation("D", 9, "1/1/2012", 1)); //retVal.Add(new InstalationEmissionDateInformation("D", 3, "1/2/2012", 1)); //retVal.Add(new InstalationEmissionDateInformation("D", 6, "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 John,
I am just checking if you got this worked out or you still require any assistance or clarification on the matter.
That helps. Thanks