Neil Alderson
Top achievements
Rank 1
Neil Alderson
asked on 15 Jan 2010, 09:46 AM
Hi Telerik,
We recently purchased your Silverlight controls for one of our new projects. I'm trying to something a little complicated with the chart control but I'm not sure how to approach it. Basically I have a collection of items like so:
Date Category
01/01/2010 00:00 Category1
01/01/2010 01:00 Category2
02/01/2010 06:00 Category2
01/01/2010 10:00 Category1
02/01/2010 20:00 Category1
What I would like to do is have a bar chart, one bar per Category
DateTime along the X-Axis
Count of Categories per day along the Y-Axis.
So far I've managed to use your grouping function and Count aggregator to achieve a count of categories over time, however what I'm struggling to achieve is aggregating the count per day, instead I have a count per exact datetime.
Please could you give me some hints as to how I can manipulate the data in the way I would like?
Kind Regards,
Neil
We recently purchased your Silverlight controls for one of our new projects. I'm trying to something a little complicated with the chart control but I'm not sure how to approach it. Basically I have a collection of items like so:
Date Category
01/01/2010 00:00 Category1
01/01/2010 01:00 Category2
02/01/2010 06:00 Category2
01/01/2010 10:00 Category1
02/01/2010 20:00 Category1
What I would like to do is have a bar chart, one bar per Category
DateTime along the X-Axis
Count of Categories per day along the Y-Axis.
So far I've managed to use your grouping function and Count aggregator to achieve a count of categories over time, however what I'm struggling to achieve is aggregating the count per day, instead I have a count per exact datetime.
Please could you give me some hints as to how I can manipulate the data in the way I would like?
Kind Regards,
Neil
5 Answers, 1 is accepted
0
Accepted
Hi Neil Alderson,
Unfortunately you cannot do this out-of-the-box with the chart, however, there is an easy work-around. You can use LINQ to project your data and round it to the day.
Consider this sample code:
Hope this helps.
Greetings,
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.
Unfortunately you cannot do this out-of-the-box with the chart, however, there is an easy work-around. You can use LINQ to project your data and round it to the day.
Consider this sample code:
public
class
BusinessObject
{
public
string
Category {
get
;
set
; }
public
DateTime Date {
get
;
set
; }
}
DateTime now = DateTime.Now;
List<BusinessObject> list =
new
List<BusinessObject>();
for
(
int
i = 0; i < 10; i++)
{
for
(
int
j = 0; j < 10; j++)
{
list.Add(
new
BusinessObject() { Category =
"A"
, Date = now });
now = now.AddMinutes(1);
}
now = now.AddDays(1);
}
var result = from item
in
list select
new
BusinessObject() { Category = item.Category, Date =
new
DateTime(item.Date.Year, item.Date.Month, item.Date.Day) };
Hope this helps.
Greetings,
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
Neil Alderson
Top achievements
Rank 1
answered on 21 Jan 2010, 09:05 AM
Thanks for your response. Actually this is how I ended up solving this problem, so I've marked it as the answer.
Neil
Neil
0
Tim
Top achievements
Rank 1
answered on 16 Mar 2010, 05:09 AM
I too am running into this situation where the end-user can select how they want the time (x-axis) to be grouped (Yearly, Monthly, etc). It would be nice if the ChartGroupDescriptor supported a custom function that could be used to return a value. This would give almost the same functionality as an "ItemDataBind" event.
So in the example above, my code (either in Code Behind or in VM) would return "DateTime.Year" or whatever it needed to depending on what the user selected.
<telerikCharting:SeriesMapping.GroupingSettings> |
<telerikCharting:GroupingSettings> |
<telerikCharting:GroupingSettings.GroupDescriptors> |
<telerikCharting:ChartGroupDescriptor MemberFunction="FormatDate(#X)"/> |
<telerikCharting:ChartGroupDescriptor Member="Region"/> |
</telerikCharting:GroupingSettings.GroupDescriptors> |
</telerikCharting:GroupingSettings> |
</telerikCharting:SeriesMapping.GroupingSettings> |
So in the example above, my code (either in Code Behind or in VM) would return "DateTime.Year" or whatever it needed to depending on what the user selected.
0
Hello Tim,
That's an excellent idea! We should definitely consider this approach. What kinds of time intervals would you like to see included? Day, Week, Month, Year?
All the best,
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.
That's an excellent idea! We should definitely consider this approach. What kinds of time intervals would you like to see included? Day, Week, Month, Year?
All the best,
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.
0
Tim
Top achievements
Rank 1
answered on 18 Mar 2010, 03:24 PM
Well, what I meant was that the developer could create a custom function in their code-behind or View Model that the GroupDescriptor would call passing in any arguments needed (in my above example I was passing in #X to get the information about the data in the x-axis). But, if the chart somehow just supported aggregated Dates by Hour, Day, Week, Month, Quarter, Year, etc, I guess that would be great! At this time, using the charts with Dates is very intensive because I have a flat datasource of data with a Date and I am writing several LINQ queries just to "group" the data first before passing it to the Chart.