RadChart Grouping and aggreate function.

Thread is closed for posting
2 posts, 0 answers
  1. Joan
    Joan avatar
    29 posts
    Member since:
    Feb 2013

    Posted 12 Apr 2013 Link to this post

    Hi Telerik Team. I made a last post but no answer so I thought I didnt explain enough, so starting again. 
    I need to show in a Chart bars during the current year (starting from January to december) the total of the booking done per month. 
    For example I have on my DB table (BookingDate, BookingValue). 

    BookingDate      BookingValue

    1/1/2013              3
    3/1/2013              6
    13/2/2013            5
    3/4/2013              3
    13/4/2013            15

    When I do a query to my DB I get a list of BookingObject: List<BookingObject>, this will be my ObjectDataSource.
    What I need to do is to show all the booking per month in the current year. My X will be 1,2,3,4..12 months and my Y the BookingValue.
    I need to show all month (1-12) even if I dont have booking for that month.

    I was trying to do it but really dont have idea, how to Sum the bookingValue per month and Grouping by Month, because I have on the Object Date and not month. 
    If anyone can help me I would appreciate it.
    Thanks in advance.

  2. Petar Kirov
    Petar Kirov avatar
    425 posts

    Posted 17 Apr 2013 Link to this post

    Hi Joan,

    The RadChart does not support aggregating data out-of-the-box, however you can relatively easy achieve that with a simple LINQ query like this:
    var result = from bookingObj in initialData
             group bookingObj by bookingObj.BookingDate.Month
             into bookingPerMonth select new PlotInfo()
                 XVal = bookingPerMonth.First().BookingDate.Month,
                 YVal = bookingPerMonth.Sum(b => b.BookingValue)
    (initialData is a List<BookingObject>, аnd the XVal and YVal properties of the PlotInfo class are numerical)
    I have attached a sample project to help you get started.
    I hope this helps.
    All the best,
    Petar Kirov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top