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

Order of points in CategoricalAxis

3 Answers 136 Views
Chart
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
AbdouMoumen
Top achievements
Rank 1
AbdouMoumen asked on 23 May 2012, 12:57 AM
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.

3 Answers, 1 is accepted

Sort by
0
Victor
Telerik team
answered on 23 May 2012, 08:39 AM
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 >>

0
AbdouMoumen
Top achievements
Rank 1
answered on 23 May 2012, 04:58 PM
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).
0
Georgi
Telerik team
answered on 23 May 2012, 05:14 PM
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 >>

Tags
Chart
Asked by
AbdouMoumen
Top achievements
Rank 1
Answers by
Victor
Telerik team
AbdouMoumen
Top achievements
Rank 1
Georgi
Telerik team
Share this question
or