This is a migrated thread and some comments may be shown as answers.

Chart Aggregation

1 Answer 59 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jara
Top achievements
Rank 1
Jara asked on 21 Mar 2011, 08:47 PM
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

1 Answer, 1 is accepted

Sort by
0
Jara
Top achievements
Rank 1
answered on 22 Mar 2011, 11:11 AM
It's O.K.
The problem is solved :)

Jara
Tags
Chart
Asked by
Jara
Top achievements
Rank 1
Answers by
Jara
Top achievements
Rank 1
Share this question
or