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

Grouping on X-Axis

2 Answers 126 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Anonymous
Top achievements
Rank 1
Anonymous asked on 05 Apr 2013, 07:29 AM
If I have an object that looks like this:
Object
customerid
value
date

I now want to have the X-axis grouped on the customerid (the same id occurs more than once). This I can do with the CategoryBinding. I'm using a ChartDataSource as the ItemSource for the Series.
Now all the values of the customerId will be displayed next to each other. What I would want to do is to only show one bar for each of the customerId and the value to use an aggregate function (e.g. sum, mean, min, max). The best way I have been able to do this is with the SamplingThreshold. But this is not correct as it could generate multiple bars for one customerId while another one is not displayed at all as the number of occurrences differ. 
I am able to show the aggregated value grouped on date using SamplingUnit and SampleInterval. But I also want to be able to group on other types than just dates.

I am doing this all in code-behind.

I might have missed something completely or be doing something wrong but I have not found a way to achieve it.
How should I go about doing this?

2 Answers, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 10 Apr 2013, 09:23 AM
Hi,

The ChartDataSource does not provide grouping and that is why you will have to implement it yourself.
I have attached a sample project where you can see an example of that. 
To use the demonstrated approach in your project, you can copy-paste the AggregateFunctions<T> class and the GroupData<T> method. To use them you need to call GroupData<T> method where T is your business class, the first parameter is a collection of data that has to be grouped, the next is parameter is where you specify the aggregate function, the next two are where you specify the value property and the category property and the last is where the property by which you want to group is.

I hope this helps.
 
Regards,
Petar Kirov
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Anonymous
Top achievements
Rank 1
answered on 10 Apr 2013, 11:31 AM
Thank you very much for your answer. I was hoping I would not have to do the grouping myself but I guess I was prepared for it. 

I can't really reuse the code because of my "real project" is much more complex but it was a good example.

I will write another post if (when? ^^) I encounter any more problems.
Tags
ChartView
Asked by
Anonymous
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Anonymous
Top achievements
Rank 1
Share this question
or