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

Unexpected date output for X-axis labels

1 Answer 47 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Greg
Top achievements
Rank 1
Greg asked on 06 Dec 2011, 02:32 PM
So I'm binding a list of custom business objects to a rad chart, for this instance, an overview of monthly revenue for a year. The dates that I'm setting for the X-axis Label aren't rendered as what I've set them at all.

Here's my basic code, you can see that get a list of monthLedger objects for a given year. The monthLedger object has different properties, but the main ones for this scenario are monthLedger.Full_date and monthLedger.Revenue_Amount.

List<monthLedger> year = getYearRevenueByMonth(2011);
 
 DataSeries ser = new DataSeries();
 
foreach(monthLedger month in year)
    {
     ser.Add(new DataPoint { YValue = Convert.ToDouble(month .Revenue_Amount), Label = month .Revenue_Amount.ToString("0.00###"), XValue = month.Full_Date.ToOADate()});
    }
 

radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
radChart1.DefaultView.ChartArea.AxisX.AutoRange = true;
radChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd-MMM";
radChart1.DefaultView.ChartArea.DataSeries.Add(ser);



Here is the data that I would get in the list for 2011 (Full_Date || Revenue_Amount): 
  • {01/01/2011 12:00:00 AM}  ||  0.00
  • {01/02/2011 12:00:00 AM}  ||  0.00
  • {01/03/2011 12:00:00 AM}  ||  0.00
  • {01/04/2011 12:00:00 AM}  ||  0.00
  • {01/05/2011 12:00:00 AM}  ||  0.00
  • {01/06/2011 12:00:00 AM}  ||  0.00
  • {01/07/2011 12:00:00 AM}  ||  0.00
  • {01/08/2011 12:00:00 AM}  ||  0.00
  • {01/09/2011 12:00:00 AM}  ||  0.00
  • {01/10/2011 12:00:00 AM}  ||  0.00
  • {01/11/2011 12:00:00 AM}  ||  246.50
  • {01/12/2011 12:00:00 AM}  ||  311.60

What I expect to get is a nice chart with 12 months, but 13 columns end up being graphed and the dates labeled are not at all the same as the ones I've converted to OLE Automation Date.

I've attached a screenshot of the graphic result.

What am I doing wrong?

1 Answer, 1 is accepted

Sort by
0
Ves
Telerik team
answered on 09 Dec 2011, 09:13 AM
Hi Greg,

When using XValue, the X axis is continuous i.e. items with close XValues will appear close to each other, while others might be away from them (e.g. Jan 1 and Jan10 will be close, while Dec 10, will appear away from them). However, months are not equal -- some are 30 days long, others -- 31 and February is 28 or 29. RadChart tries to produce a reasonable step for X axis, however with the irregular months length that is not possible. This is visible in your screenshot -- with a step of 30 days, the second label is Jan 31st, that is 30 days after the first one. Slowly the error adds up, so the last item is Dec 27.

My suggestion here would be to use a categorical chart. Just set XCategory rather than XValue (XCategory = month.Full_Date.ToString("dd-MMM"). This way the chart will display the months just as regular strings and there will be one X axis slot for each distinct value.

Best regards,
Ves
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

Tags
Chart
Asked by
Greg
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or