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

Problems with XAxis dates, labelin, XValue vs XCategory

1 Answer 66 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.
Douglas
Top achievements
Rank 1
Douglas asked on 23 Mar 2012, 05:51 PM
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.



1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 28 Mar 2012, 12:27 PM
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));
this.TheChart.SeriesMappings.Add(series1);
  
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));
this.TheChart.SeriesMappings.Add(series2);

Hope this helps! Regards,
Yavor
the Telerik team
Sharpen your .NET Ninja skills! Attend Q1 webinar week and get a chance to win a license! Book your seat now >>
Tags
Chart
Asked by
Douglas
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or