Help on weird graph

3 posts, 0 answers
  1. Benny
    Benny avatar
    2 posts
    Member since:
    Nov 2012

    Posted 29 Nov 2012 Link to this post

    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. Missing user
    Missing user avatar

    Posted 04 Dec 2012 Link to this post

    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.

  3. DevCraft banner
  4. Benny
    Benny avatar
    2 posts
    Member since:
    Nov 2012

    Posted 13 Dec 2012 Link to this post

    Thanks a lot Ivan. I will try your solution.
Back to Top