Grouping on X-Axis

3 posts, 0 answers
  1. Anonymous
    Anonymous avatar
    2 posts
    Member since:
    Dec 2012

    Posted 05 Apr 2013 Link to this post

    If I have an object that looks like this:

    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. Petar Kirov
    Petar Kirov avatar
    425 posts

    Posted 10 Apr 2013 Link to this post


    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.
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

  3. Anonymous
    Anonymous avatar
    2 posts
    Member since:
    Dec 2012

    Posted 10 Apr 2013 Link to this post

    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.
Back to Top