Chart Aggregation

2 posts, 0 answers
  1. Jara
    Jara avatar
    29 posts
    Member since:
    Jul 2010

    Posted 21 Mar 2011 Link to this post

    Hi,
    I am using this version 2010.3 1314 of product and want to do something like this:
    http://demos.telerik.com/silverlight/#Chart/Aggregates
    (Chart grouping and aggregetion)

    It's my grid:
     <telerik:RadGridView x:Name="ctlrGridView" AutoGenerateColumns="false" RowHeight="20" IsFilteringAllowed="True" Grid.Column="0" Grouped="ctlrGridView_Grouped" ItemsSource="{Binding Path=DataTable, Mode=TwoWay}" >
                <telerik:RadGridView.Columns>              
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Customer}" Header="Klientas" Width="0.5*"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Title}" Header="Data" DataFormatString="{}{0:yyy-MM-dd}" Width="0.25*"/>
                    <telerik:GridViewDataColumn DataMemberBinding="{Binding Path=Debt}" Header="Skola" Width="0.25*" IsGroupable="False" />                   
                </telerik:RadGridView.Columns>
            </telerik:RadGridView>

    and there is chart:
    <telerik:RadChart x:Name="ctlrAggregationChart" >
    </telerik:RadChart>

    I write a method:
    private void Binding_ctlrAggregationChart()
            {
             
                ctlrAggregationChart.ItemsSource = null;
                ctlrAggregationChart.SeriesMappings.Clear();

                SeriesMapping mapping1 = new SeriesMapping();

                ChartAggregateFunction aggFunct = (ChartAggregateFunction)Enum.Parse(typeof(ChartAggregateFunction), (this.cmbAggregation.SelectedItem as RadComboBoxItem).Content as string, true);

                mapping1.ItemMappings.Add(new ItemMapping("Pelnas", DataPointMember.YValue, aggFunct));
                mapping1.SeriesDefinition = new BarSeriesDefinition();

                foreach (Telerik.Windows.Data.GroupDescriptor descriptor in ctlrGridView.GroupDescriptors)           
                {
                    mapping1.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor((descriptor as Telerik.Windows.Data.GroupDescriptor).Member));
                }

                if (ctlrGridView.GroupDescriptors.Count > 1 && (cmbAggregation.SelectedItem as RadComboBoxItem).Content.ToString().ToLower() != "none")
                {
                    Telerik.Windows.Data.GroupDescriptor lastGroupDescriptor = (Telerik.Windows.Data.GroupDescriptor)ctlrGridView.GroupDescriptors[ctlrGridView.GroupDescriptors.Count - 1];
                    mapping1.ItemMappings.Add(new ItemMapping(lastGroupDescriptor.Member, DataPointMember.XCategory));
                }
               

                mapping1.SeriesDefinition.ItemLabelFormat = "#Y{C0}";
               
                ctlrAggregationChart.DefaultView.ChartArea.AxisY.DefaultLabelFormat = "C";
                ctlrAggregationChart.SeriesMappings.Add(mapping1);
                ctlrAggregationChart.DefaultView.ChartArea.AxisY.Title = "Pelnas";
                ctlrAggregationChart.DefaultView.ChartArea.AxisX.LayoutMode = AxisLayoutMode.Between;

                ctlrAggregationChart.ItemsSource = ctlrGridView.ItemsSource;  ///// WHERE I get ERROR !!! NullReferenceException


            }

    I attach a print screen with error.
    Maybe someone can tell me, what I am doing wrong, or post a simple working example.
    In previous version this code work perfectly, but in 2010.3 1314 version not, or maybe I make somewhere mistakes.

    Thanks,
    Jara
  2. Jara
    Jara avatar
    29 posts
    Member since:
    Jul 2010

    Posted 22 Mar 2011 Link to this post

    It's O.K.
    The problem is solved :)

    Jara
Back to Top