Hello,
I am getting a problem when I try to paint some data, I have 2 options to choose in 2 combobox:
Installations or Enterprises
Year
My problem comes when I change from Installation to Enterprise. By default it paint data of the installations in a correct way, even if I change the year. The problem goes when changing to Enterprises. It paints only a few info of the data. From 60 registry it paints only 12.
I have tried doing in the other way, painting by default first of all the Enterprises and afterwards the installations and the result is the same.
My code behind is this one (this is on my server, I use silverlight):
public List<ExcessVsEmissions> GetValuesOfExcessVsEmissionsEnterprise(int year) { var TestEmissionsCollection = new List<ExcessVsEmissions>(); for (int i = 1; i <= 12; i++) { TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 4500, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 4000, Id = new Guid(), Name = "Enterprise 1", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 3500, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 2000, Id = new Guid(), Name = "Enterprise 2", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 2000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 1800, Id = new Guid(), Name = "Enterprise 3", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 10000, Date =(i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 10000 - 7800, Id = null, Name = "Emisiones Totales", ParentId = null, }); } return TestEmissionsCollection; } public List<ExcessVsEmissions> GetValuesOfExcessVsEmissionsInstallation(int year) { var TestEmissionsCollection = new List<ExcessVsEmissions>(); for (int i = 1; i <= 12; i++) { TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 500, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 400, Id = new Guid(), Name = "Instalacion 1", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 1000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 1100, Id = new Guid(), Name = "Instalacion 2", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 2000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 500, Id = new Guid(), Name = "Instalacion 3", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 3000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 2800, Id = new Guid(), Name = "Instalacion 4", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 4000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 3000, Id = new Guid(), Name = "Instalacion 5", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 10000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 10000 - 7800, Id = null, Name = "Emisiones Totales", ParentId = null, }); } return (TestEmissionsCollection); }
Each time I change my filter to installation or enterprise, it calls one or another method.
And in my View:
<UserControl.Resources> <igChart:GroupBy x:Key="grouped" ItemsSource="{Binding ValuesOfExcessVsEmissions,Mode=TwoWay}" GroupMemberPath="Date" KeyMemberPath="Name" ValueMemberPath="Emission" /> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <ig:XamDataChart x:Name="theChart" Grid.Row="1" Visibility="{Binding ShowDataChart,Mode=TwoWay}" > <ig:XamDataChart.Axes> <ig:CategoryXAxis x:Name="xAxis" ItemsSource="{StaticResource grouped}" Interval="1" Label="{}{Key}"/> < <ig:NumericYAxis x:Name="yAxis" Interval="500" MinimumValue="{Binding MinAssignation, Mode=TwoWay}" MaximumValue="{Binding MaxAssignation, Mode=TwoWay}"/> </ig:XamDataChart.Axes> <ig:XamDataChart.Series> <ig:StackedColumnSeries x:Name="stack" ItemsSource="{StaticResource grouped}" XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis}" AutoGenerateSeries="True" LegendItemVisibility="Visible"> </ig:StackedColumnSeries> </ig:XamDataChart.Series> </ig:XamDataChart> </Grid>
My ViewModel will Have this in the event that receives the data from the server:
if (e.Result != null) { ValuesOfExcessVsEmissions = new ObservableCollection<ExcessVsEmissions>(e.Result); ShowDataChart = Visibility.Visible; }And my Model looks like this:
public class ExcessVsEmissions { private Guid? _parentId; public Guid? ParentId { get { return _parentId; } set { _parentId = value; } } private Guid? _id; public Guid? Id { get { return _id; } set { _id = value; } } private string _name; public string Name { get { return _name; } set { _name = value; } } private Decimal? _emission; public Decimal? Emission { get { return _emission; } set { _emission = value; } } private string _date; public string Date { get { return _date; } set { _date = value; } } private Decimal? _assignation; public Decimal? Assignation { get { return _assignation; } set { _assignation = value; } } }So, why is happening this? I have also tried to add Notify property changedto my model, but with no luck.Any idea? Thank you.PS: By the way, how can I put a tooltip or legend to the Namewhen I have Groupedby in my view?
There is no answer for this problem? I am testing different charts and I want to know if yours are the best for the project
The stacked chart doesn't currently listen for the keys and auto generate the series again. The best thing for you to do would be to put the GroupBy in your view model, and change the group by when the data source changes as well.Here is an example:
<UserControl.Resources> <local:KeyConverter x:Key="keyConverter" /> <DataTemplate x:Key="keyLegendItemTemplate"> <StackPanel Orientation="Horizontal" Margin="1" Visibility="{Binding Series.Visibility}"> <ContentPresenter Content="{Binding}" ContentTemplate="{Binding Series.LegendItemBadgeTemplate}" /> <ContentPresenter Content="{Binding Series.ValueMemberPath, Converter={StaticResource keyConverter}, ConverterParameter='_Emission'}"/> </StackPanel> </DataTemplate> </UserControl.Resources> <Grid x:Name="LayoutRoot" Background="White"> <Grid.ColumnDefinitions> <ColumnDefinition /> <ColumnDefinition Width="Auto" /> </Grid.ColumnDefinitions> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition Height="Auto" /> </Grid.RowDefinitions> <igChart:XamDataChart x:Name="theChart" Legend="{Binding ElementName=legend1}"> <igChart:XamDataChart.Axes> <igChart:CategoryXAxis x:Name="xAxis" ItemsSource="{Binding Data}" Label="{}{Key}"/> <igChart:NumericYAxis x:Name="yAxis" /> </igChart:XamDataChart.Axes> <igChart:XamDataChart.Series> <igChart:StackedColumnSeries x:Name="stack" ItemsSource="{Binding Data}" XAxis="{Binding ElementName=xAxis}" YAxis="{Binding ElementName=yAxis}" AutoGenerateSeries="True" LegendItemTemplate="{StaticResource keyLegendItemTemplate}" > </igChart:StackedColumnSeries> </igChart:XamDataChart.Series> </igChart:XamDataChart> <igChart:Legend x:Name="legend1" Grid.Column="1" /> <Button Grid.Row="1" x:Name="changeData" Content="Change Data" Click="changeData_Click" /> </Grid> </UserControl>
and code behind:
public partial class MainPage : UserControl, INotifyPropertyChanged { public MainPage() { InitializeComponent(); Data = new GroupBy() { ItemsSource = GetValuesOfExcessVsEmissionsEnterprise(2000), GroupMemberPath = "Date", KeyMemberPath = "Name", ValueMemberPath = "Emission" }; DataContext = this; } private GroupBy _data; public GroupBy Data { get { return _data; } set { _data = value; if (PropertyChanged != null) { PropertyChanged( this, new PropertyChangedEventArgs( "Data")); } } } public List<ExcessVsEmissions> GetValuesOfExcessVsEmissionsEnterprise(int year) { var TestEmissionsCollection = new List<ExcessVsEmissions>(); for (int i = 1; i <= 12; i++) { TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 4500, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 4000, Id = new Guid(), Name = "Enterprise 1", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 3500, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 2000, Id = new Guid(), Name = "Enterprise 2", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 2000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 1800, Id = new Guid(), Name = "Enterprise 3", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 10000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 10000 - 7800, Id = null, Name = "Emisiones Totales", ParentId = null, }); } return TestEmissionsCollection; } public List<ExcessVsEmissions> GetValuesOfExcessVsEmissionsInstallation(int year) { var TestEmissionsCollection = new List<ExcessVsEmissions>(); for (int i = 1; i <= 12; i++) { TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 500, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 400, Id = new Guid(), Name = "Instalacion 1", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 1000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 1100, Id = new Guid(), Name = "Instalacion 2", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 2000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 500, Id = new Guid(), Name = "Instalacion 3", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 3000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 2800, Id = new Guid(), Name = "Instalacion 4", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 4000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 3000, Id = new Guid(), Name = "Instalacion 5", ParentId = null, }); TestEmissionsCollection.Add(new ExcessVsEmissions() { Assignation = 10000, Date = (i.ToString() + " / " + year.ToString()[2] + year.ToString()[3]), Emission = 10000 - 7800, Id = null, Name = "Emisiones Totales", ParentId = null, }); } return (TestEmissionsCollection); } public event PropertyChangedEventHandler PropertyChanged; private void changeData_Click(object sender, RoutedEventArgs e) { Data = new GroupBy() { ItemsSource = GetValuesOfExcessVsEmissionsInstallation(2000), GroupMemberPath = "Date", KeyMemberPath = "Name", ValueMemberPath = "Emission" }; } } public class ExcessVsEmissions { private Guid? _parentId; public Guid? ParentId { get { return _parentId; } set { _parentId = value; } } private Guid? _id; public Guid? Id { get { return _id; } set { _id = value; } } private string _name; public string Name { get { return _name; } set { _name = value; } } private Decimal? _emission; public Decimal? Emission { get { return _emission; } set { _emission = value; } } private string _date; public string Date { get { return _date; } set { _date = value; } } private Decimal? _assignation; public Decimal? Assignation { get { return _assignation; } set { _assignation = value; } } } public class KeyConverter : IValueConverter { public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { if (value is string && parameter is string) { var key = (string)value; var param = (string)parameter; key = key.Replace(param, ""); return key; } return ""; } public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) { throw new NotImplementedException(); } }
Hope this helps!-Graham
It works now, thank you very much!!
I will hit now for the legend that is not really working and I will try to put a tooltip foreach stacked item