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

Help on weird graph

2 Answers 51 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Benny
Top achievements
Rank 1
Benny asked on 29 Nov 2012, 10:05 PM
Really appreciate if anyone could help me on the weird graph I've got. It just does not want to draw the line between two datapoints some times (not always, please see attached image). If I refresh the page to reload data several times, it works fine.

2 Answers, 1 is accepted

Sort by
0
Missing User
answered on 04 Dec 2012, 04:16 PM
Hi Benny,

Your problem may be caused by passing unsorted data to the RadChart. While the chart does position each object according to the X axis, it doesn't connect it to its neighbor relative to the X axis, but rather to its corresponding neighbor from the underlying data source.
Consider this example:
this.RadChart1.DataContext = new List<KeyValuePair<DateTime, int>>()
{
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 3), 3),
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 4), 1),
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 5), 2),
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 6), 4)
};
In this case, the KeyValuePairs are sorted by Key (DateTime) in advance, so the chart will render as shown in the attached chart_sorted.jpg file.

On the other hand, should you populate the chart like this:
this.RadChart1.DataContext = new List<KeyValuePair<DateTime, int>>()
{
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 4), 1),
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 5), 2),
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 3), 3),
    new KeyValuePair<DateTime, int>(new DateTime(2012, 12, 6), 4)
};
That is, should you populate the chart with unsorted data, it will render as shown in the attached chart_unsorted.jpg file.

Note that in both cases the data points are sorted relative to the X axis, but the order in which they are connected depends on the way they've been passed to the RadChart.

Kind regards,
Ivan N.
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Benny
Top achievements
Rank 1
answered on 13 Dec 2012, 08:59 PM
Thanks a lot Ivan. I will try your solution.
Tags
Chart
Asked by
Benny
Top achievements
Rank 1
Answers by
Missing User
Benny
Top achievements
Rank 1
Share this question
or