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

ChartAggregateFunction problem

8 Answers 187 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Ludovic Gerbault
Top achievements
Rank 1
Ludovic Gerbault asked on 14 Nov 2009, 02:00 PM
Hello

I'm having some issue implementing the Integration example between a chart and a grid using grouping.

Here's the thing, I have my radgrid bound to a collection of string objects, the grid binds fine.
The Y value is one of these string objects, that can be converted into a double or a decimal.

But for some reason, when I use the sum aggregate function, I get an error saying No method Sum compatible from the type System.Linq.Enumerable with the provided arguments.

So I'm guessing that because in the itemsource, every object is a string, the chart won't even try to convert it, even though it is possible.

Do you know of a way around this problem, do I need to override the chartaggregatefuntion to write my own one, do you plan to implement some convert functionnality, or am I screwed ??

Thanks.

Ludovic

8 Answers, 1 is accepted

Sort by
0
Vladimir Milev
Telerik team
answered on 18 Nov 2009, 12:45 PM
Hi Subileau Pascal,

Indeed there is no Sum function which works with an IEnumerable of string objects. This behavior is by design.

I will suggest the following:
-You can create a ViewModel object which parses the strings and returns IEnumerable of doubles (preparing your data for use by the Chart).
-If your class is partial you can create a wrapper property which converts the string to double and you can map it to the YValue.

The ChartAggregate function is a derived class from the one used in the RadGridView so they are basically the same time. Also, deriving from it will not help.

Sincerely yours,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ludovic Gerbault
Top achievements
Rank 1
answered on 16 Dec 2009, 02:27 PM
Hello guys

I'm getting back on a similar problem.

I've changed my source collection to an IList of a class composed exclusively of Object attributes (Object attributea, Object attributeb...)

In this class logic, when I'm building the collection (in ASP, not yet in silverlight since this IList is return through WCF), I'm using several tryparse method to have all the data typed correctly.

The grid recognized the int or decimal attributes as such, since I can now sort numerically, not alphabetically as I used to.

But the radchart sum aggregate method still doesn't recognized that the itemmapping is set on a numeric value, and return "no Sum method is applicable for the elements provided"

So, It doesn't work on a string collection, but it doesn't work either on an Object typed as int collection ?
0
Vladimir Milev
Telerik team
answered on 18 Dec 2009, 12:56 PM
Hello Subileau Pascal,

Actually the underlying data engine responsible for the grouping and aggregation in RadChart is the same as the one used in the RadGridView control. The data core is the same code and if it works in the grid it should work in the chart.

With that said we are concerned about the possibility that there is a bug somewhere. Can you send us a small runnable sample isolating the problem so that we can have a look at it?

Thanks a lot in advance.

Regards,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Ludovic Gerbault
Top achievements
Rank 1
answered on 18 Dec 2009, 01:18 PM
Well, I've found a workaround my problem using the lightweight datatable an tolist extensions method, but I'll try to make a sample project reproducing my earlier problem this evening.
0
Ludovic Gerbault
Top achievements
Rank 1
answered on 07 Jan 2010, 11:36 AM
I have a question about the RadChart grouping integration.

As far as I understand how telerik's logic work, the last groupdescritpor of the grid is used to bind the XCategory property, all the others are bind to the legendlabel.

Am I correct ?

If it's the case, is there a way for it to be the other way around, I mean, having the first groupdescriptor to be the XCategory, and the other ones being the legendlabel ?
0
Vladimir Milev
Telerik team
answered on 12 Jan 2010, 09:31 AM
Hello Subileau Pascal,

Group descriptors and mappings are not directly related. Group descriptors and aggregates are used to produce a set of aggregated data objects which then are used to data bind the chart according to the item mappings. Grouping occurs according to the order you have added the group descriptors. The XCategory is bound as directed by the ItemMapping - not the group descriptor.

The whole process is nicely explained in this help topic. Hope it clears things up.

Sincerely yours,
Vladimir Milev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
kjellerik
Top achievements
Rank 1
answered on 21 Apr 2010, 07:59 AM

Hi,

We are using MVVM, and observablecollection as itemssource to dispaly operations in a gridview. We would like to use the grouping in the gridview to create a chart summing up a "operation_duration" property, as done in the Grouping and Aggregation example in the Chart demos. The binding to the itemssource seems to work as do the grouping, however when we add any aggregation we get the following error:

{System.NullReferenceException: Object reference not set to an instance of an object.  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.ExtractValueFromAggregateFunctionsGroup(AggregateFunctionsGroup aggregateFunctionsGroup, AggregateFunction aggregateFunction)  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.CreateDataSeriesBasedOnAggregationGroups(SeriesMapping seriesMapping, ISeriesDefinition defaultSeriesDefinition, IEnumerable`1 topLevelGroups)  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.CreateDataSeriesWithAggregation(SeriesMapping seriesMapping, ISeriesDefinition defaultSeriesDefinition, IGroup workingGroup, IEnumerable`1 sourceGroups, IEnumerable`1 topLevelGroups)  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.ProcessGroupingWithAggregation(SeriesMapping seriesMapping, QueryableCollectionView dataEngine, ISeriesDefinition defaultSeriesDefinition)  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.ProcessGrouping(SeriesMapping seriesMapping, QueryableCollectionView dataEngine, Int32 samplingThreshold, ZoomScrollSettings zoomScrollSettings, ISeriesDefinition defaultSeriesDefinition, AxisRangeState axisXRangeState, Int32 seriesCount)  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.ProcessMapping(SeriesMapping seriesMapping, QueryableCollectionView dataEngine, Int32 samplingThreshold, ZoomScrollSettings zoomScrollSettings, ISeriesDefinition defaultSeriesDefinition, AxisRangeState axisXRangeState, Int32 seriesCount)  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.ProcessMappings(SeriesMappingCollection seriesMappings, QueryableCollectionView dataEngine, Int32 samplingThreshold, ZoomScrollSettings zoomScrollSettings, ISeriesDefinition defaultSeriesDefinition, AxisRangeState axisXRangeState)  
   at Telerik.Windows.Controls.Charting.DataBindingHelper.GenerateDataSeries(Object originalData, SeriesMappingCollection seriesMappings, ISeriesDefinition defaultSeriesDefinition, ChartFilterDescriptorCollection globalFilterDescriptors, ChartSortDescriptorCollection globalSortDescriptors, SamplingSettings samplingSettings, ZoomScrollSettings zoomScrollSettings, AxisRangeState axisXRangeState)  
   at Telerik.Windows.Controls.RadChart.GenerateDataSeries(Object originalData, SeriesMappingCollection seriesMappings, ChartArea chartArea)  
   at Telerik.Windows.Controls.RadChart.GenerateDataSeries(Object originalData)  
   at Telerik.Windows.Controls.RadChart.Rebind(Object originalData)  
   at Telerik.Windows.Controls.RadChart.ItemsSourcePropertyChanged(DependencyObject target, DependencyPropertyChangedEventArgs args)  
   at Telerik.Windows.PropertyMetadata.<>c__DisplayClass1.<Create>b__0(DependencyObject d, DependencyPropertyChangedEventArgs e)  
   at System.Windows.DependencyObject.RaisePropertyChangeNotifications(DependencyProperty dp, Object oldValue, Object newValue)  
   at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)  
   at System.Windows.DependencyObject.SetValueInternal(DependencyProperty dp, Object value, Boolean allowReadOnlySet)  
   at System.Windows.DependencyObject.SetValue(DependencyProperty dp, Object value)  
   at Telerik.Windows.Controls.RadChart.set_ItemsSource(Object value)  
   at DBRWeb.Client.IncidentPivotTableTest.View.PivotTableView.BindChart()  
   at DBRWeb.Client.IncidentPivotTableTest.View.PivotTableView.radGridView1_Grouped(Object sender, GridViewGroupedEventArgs e)} 

here is the code. If i remove the "aggFunct" variable in map1.ItemMappings.Add(new ItemMapping("Operation_Duration", .. ) I do not get any errors, but creates one bar for each "Operation_Duration" grouped as in the gridview:

private void radGridView1_Grouped(object sender, Telerik.Windows.Controls.GridViewGroupedEventArgs e)  
        {  
            this.BindChart();  
        }  
 
        private void BindChart()  
        {  
            radChart1.ItemsSource = null;  
            radChart1.SeriesMappings.Clear();  
 
            SeriesMapping map1 = new SeriesMapping();  
            map1.SeriesDefinition = new BarSeriesDefinition();  
 
            ChartAggregateFunction aggFunct = ChartAggregateFunction.Sum;  
            //map1.ItemMappings.Add(new ItemMapping("Operation_Duration", DataPointMember.YValue));  
            map1.ItemMappings.Add(new ItemMapping("Operation_Duration", DataPointMember.YValue, aggFunct));  
 
            //ChartGroupDescriptorCollection chartGroupDescription = new ChartGroupDescriptorCollection();  
 
            foreach (GroupDescriptor descriptor in radGridView1.GroupDescriptors)  
            {  
                map1.GroupingSettings.GroupDescriptors.Add(new ChartGroupDescriptor(descriptor.Member));  
            }  
 
            if (radGridView1.GroupDescriptors.Count > 1)  
            {  
                GroupDescriptor lastGroupDescriptor = (GroupDescriptor)radGridView1.GroupDescriptors[radGridView1.GroupDescriptors.Count - 1];  
                map1.ItemMappings.Add(new ItemMapping(lastGroupDescriptor.Member, DataPointMember.XCategory));  
            }  
 
            radChart1.SeriesMappings.Add(map1);  
            //Operation[] data = new Operation[((ObservableCollection<Operation>)radGridView1.ItemsSource).Count];  
            //((ObservableCollection<Operation>)radGridView1.ItemsSource).CopyTo(data, 0);  
 
            radChart1.ItemsSource = radGridView1.ItemsSource;  
        } 

0
Vladimir Milev
Telerik team
answered on 23 Apr 2010, 02:36 PM
Hi kjellerik,

Have you tried the SP1 version of the controls release just recently? We believe you are getting this error due to a bug we fixed recently.

Also if you are continuing to experience this problem even after upgrading we would really appreciate it if you can send us a runnable sample project which demonstrates the issue.

Thanks a lot in advance!

Greetings,
Vladimir Milev
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
Chart
Asked by
Ludovic Gerbault
Top achievements
Rank 1
Answers by
Vladimir Milev
Telerik team
Ludovic Gerbault
Top achievements
Rank 1
kjellerik
Top achievements
Rank 1
Share this question
or