Question

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: enter image description here

What am I doing wrong?

Was it helpful?

Solution

As I can see from your Image the Chart plots the bars with Step of 30 days. This is caused by the Automatic Range of the XAxis. Since the Chart cannot define a punctual step of 1 month (the months has different number of days), the XAxis automatically defined that 30 days is the most appropriate. Setting a manual range won't help you so I suggest that you use an XCategory instead of XValue:

foreach(monthLedger month in year) 
   { 
    ser.Add(new DataPoint  
            {  
                YValue = Convert.ToDouble(month.Revenue_Amount),  
                Label = month.Revenue_Amount.ToString("0.00###"),  
                XCategory = month.Full_Date
            }); 
   } 

You can remove this - radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true; as it is not needed any more.

Cheers, Evgenia

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top