Databinding to custom business object fails

6 posts, 0 answers
  1. Andy
    Andy avatar
    6 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2011 Link to this post

    I'm following the the Getting started article "Create Data Bound Chart" to bind a silverlight chart to a collection of my custom business object.

    <telerik:RadChart>
                                <telerikChart:RadChart.SeriesMappings>
                                    <telerikCharting:SeriesMapping LegendLabel="Product Sales" ItemsSource="{Binding BusinessObject}">
                                        <telerikCharting:SeriesMapping.SeriesDefinition>
                                            <telerikCharting:SplineSeriesDefinition></telerikCharting:SplineSeriesDefinition>
                                        </telerikCharting:SeriesMapping.SeriesDefinition>
                                        <telerikCharting:SeriesMapping.ItemMappings>
                                            <telerikCharting:ItemMapping DataPointMember="XValue" FieldName="Timestamp"></telerikCharting:ItemMapping>
                                            <telerikCharting:ItemMapping DataPointMember="YValue" FieldName="Value"></telerikCharting:ItemMapping>
                                        </telerikCharting:SeriesMapping.ItemMappings>
                                    </telerikCharting:SeriesMapping>
                                </telerikChart:RadChart.SeriesMappings>
                            </telerik:RadChart>

    When the databinding happens I get an exception:

    InvalidOperationException
    No generic method 'Average' on type 'System.Linq.Enumerable' is compatible with the supplied type arguments and arguments. No type arguments should be provided if the method is non-generic.

    I already tried different collection types and value types in my business object which doesn't change anything. Any ideas on what I'm doing wrong?

    Thanks for your help
  2. Andy
    Andy avatar
    6 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2011 Link to this post

    Still no luck. Here is some sample code from my business object:

       public class BusinessObject   {
            
           public System.DateTime Timestamp {
              get;
              set;
           }
     
          public uint Value {
              get;
              set;
           }
            
           public uint Hits {
              get;
              set;
           }
       }

    The object I'm binding the radChart to is actually a List<BusinessObject>. (I already tried IList<>, ObservableCollection<>, ReadonlyObservableCollection<>, ...). I'm always getting the same exception when binding happens ...
  3. Andy
    Andy avatar
    6 posts
    Member since:
    Apr 2011

    Posted 12 Apr 2011 Link to this post

    Finally I narrowed down my problem a bit. The data I want to show in the chart is received using a wcf service. If I return a locally created dummy collection instead of the real wcf received data everything works as expected. When returning the actual data I got from the wcf service, I get the exception. I even tried to copy all the objects to a newly created collection and use this one for binding but it fails, too.

    Any ideas on how to solve this issue without copying all the data to new objects?
  4. Yavor
    Admin
    Yavor avatar
    11 posts

    Posted 14 Apr 2011 Link to this post

    Hello Andy,

    Based on the supplied information, it is hard to determine what is causing this exception. If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, and showing the unwanted behavior. We will debug it locally, and advise you further.
    Additionally, you can locally verify where the exception occurs - in the service itself, or when passing the data to the chart control.

    Kind regards,
    Yavor
    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
  5. Andy
    Andy avatar
    6 posts
    Member since:
    Apr 2011

    Posted 14 Apr 2011 Link to this post

    I solved this issue by myself after a lot of debugging and pure luck. Binding to an uint fails when the sampling feature of the control kicks in (more than 200 items in the data by default). This didn't happen with my test data.

    Now I got the next problem: I need to bind to another property of my business object which is of type TimeSpan which seems to be impossible without strange workarounds (and of course fails with sampling enabled). I badly need to bind multiple members with different types and the appropriate labeling on the axis.

    Disabeling sampling isn't a solution to my problem because I need to plot probably thousands of items.


  6. Missing user
    Missing user avatar

    Posted 19 Apr 2011 Link to this post

    Hello Andy,

    Presently, RadChart does not support directly binding TimeSpan values out of the box.You can try to produce a double representation of TimeSpan values, so that the chart can be databound and displayed properly, but that might lead to various difficulties in different scenarios like displaying proper labels, etc.

    Regards,
    Polina
    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
Back to Top