Problems with XAxis dates, labelin, XValue vs XCategory

2 posts, 0 answers
  1. Douglas
    Douglas avatar
    15 posts
    Member since:
    Feb 2012

    Posted 23 Mar 2012 Link to this post

    I have a Stacked Bar 100 with several SeriesMappings using CollectionIndex.  The XAxis are dates and the YAxis some value.

    When the first series/collection does not have data for the first date my XAxis gets out of order.  In particular the earliest date gets placed at the end of the range.

    Is there a way to make all the dates appear in order?  

    I am using XCategory for the SeriesMappings.  If I use XValue the dates come out fine, but then there are extra tick marks along the XAxis.  Is there a way to get rid of the extra tick marks?

    Finally, I have tried to create a custom XAxis by specifying the min and max values, step, and turning off autorange, but then nothing gets displayed in the chartarea.  Also it doesn't seem to fix the out of order issue because the dates still get listed out of order along the XAxis.  Even if my chart did display it looks like it would display out of order with a custom axis anyway.

    The only way I have been able to resolve this is to pad my data so that each collection contains all the dates.

  2. Yavor
    Yavor avatar
    401 posts

    Posted 28 Mar 2012 Link to this post

    Hi Douglas,

    In order for your categories to be displayed properly your data has to be aligned. This means that you have to have the same number of data points in each series. The additional data points that have to be inserted can be set as null and dropped from the graph by using empty point behavior. Here is some code: 

    SeriesMapping series1 = new SeriesMapping();
    series1.SeriesDefinition = new LineSeriesDefinition() { EmptyPointBehavior = EmptyPointBehavior.Drop };
    series1.ItemsSource = new List<Tuple<string, double?>>()
        new Tuple<string, double?>("A", 10),
        new Tuple<string, double?>("B", 20),
        new Tuple<string, double?>("C", null),
        new Tuple<string, double?>("D", 30),
        new Tuple<string, double?>("E", 40)
    series1.ItemMappings.Add(new ItemMapping("Item1", DataPointMember.XCategory));
    series1.ItemMappings.Add(new ItemMapping("Item2", DataPointMember.YValue));
    SeriesMapping series2 = new SeriesMapping();
    series2.SeriesDefinition = new LineSeriesDefinition() { EmptyPointBehavior = EmptyPointBehavior.Drop };
    series2.ItemsSource = new List<Tuple<string, double?>>()
        new Tuple<string, double?>("A", null),
        new Tuple<string, double?>("B", 40),
        new Tuple<string, double?>("C", 30),
        new Tuple<string, double?>("D", 20),
        new Tuple<string, double?>("E", 10)
    series2.ItemMappings.Add(new ItemMapping("Item1", DataPointMember.XCategory));
    series2.ItemMappings.Add(new ItemMapping("Item2", DataPointMember.YValue));

    Hope this helps! Regards,
    the Telerik team
    Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Back to Top