Order of points in CategoricalAxis

4 posts, 0 answers
  1. AbdouMoumen
    AbdouMoumen avatar
    6 posts
    Member since:
    Oct 2010

    Posted 22 May 2012 Link to this post

    Hi,

    I'm working with a RadChart that has a CategoricalAxis as its HorizontalAxis. The chart has a number of LineSeries bound to instances of a "IEnumerable<Point<string,int>>". The "string" in there is actually formatted from a date and a number (date as dd/mm, then the number in the next line).

    The problem I'm having is that the dates on the chart appear out of order, even though they're ordered in the series. This only happens when there is more than one series plotted. Here's an example:

    Series 1(date,value): (05/10 , 3) , (05/17 , 4)
    Series 2(date,value): (05/10 , 2) , (05/16 , 5) , (05/17 , 3) , (05/21 , 4)
    Series 3(date,value): (05/11 , 2) , (05/17 , 5) , (05/20 , 3)

    In this example, the dates on the CategoricalAxis are plotted as follows: 05/10, 05/11, 05/17, 05/16, 05/20, 05/21 (keep in mind that even though these were dates originally, they've been formatted to strings)

    As you can see, the "categories" aren't ordered correctly. I tried adding a line series with all the dates ordered and zero values but that didn't fix it.

    Is there a way to make the axis plot the values in order? should I use another axis type for this? if so, which one would suit my requirements?

    Thanks in advance.
  2. Victor
    Admin
    Victor avatar
    1351 posts

    Posted 23 May 2012 Link to this post

    Hello Bouabdallah,

    You simply need to sort your data source. Since it is an IEnumerable<Point<string, int>> you can simply use the order by Linq clause and specify the correct comparison expression. If your dates are converted to string you can simply parse them back to DateTime objects and compare those inside the comparison expression.
    Write again if you have other questions.

    Regards,
    Victor
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

  3. DevCraft banner
  4. AbdouMoumen
    AbdouMoumen avatar
    6 posts
    Member since:
    Oct 2010

    Posted 23 May 2012 Link to this post

    hello,

    The problem is that my data source IS in fact ordered. As you can see in the example, the individual series are all in order, but the resulting axis isn't. This only happens when I have multiple series in the same chart, though. When I tried it with each of the individual series they were plotted correctly.

    I just found a workaround for this (more of a hack actually), where I added a series that contained all of the dates as the first one to be plotted (with a transparent stroke).
  5. Georgi
    Admin
    Georgi avatar
    296 posts

    Posted 23 May 2012 Link to this post

    Hello,

    In your case you may try the DateTimeCategorical axis, which will automatically sort all its categories chronologically (you may need to adjust the DateTimeComponent property accordingly). Please note that in this case you will need to pass valid DateTime instances (instead of strings) as axis's categories. You can use the Category and Value bindings in each series to bind to a business object.

    Let me know whether this helps you achieve the desired result.

    Kind regards,
    Georgi
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Back to Top