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

RadChart Grouping and aggreate function.

1 Answer 72 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Joan
Top achievements
Rank 1
Joan asked on 12 Apr 2013, 05:00 PM

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.

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 17 Apr 2013, 08:54 PM
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.
Tags
Chart (Obsolete)
Asked by
Joan
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or