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

Chart do not work with date

1 Answer 31 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Paulo
Top achievements
Rank 1
Paulo asked on 20 Mar 2013, 08:09 PM
I have a range of dates. My chart needs to start on a certain date, but is beginning on the first date of the Xaxis. How do I get in a certain specific date?

1 Answer, 1 is accepted

Sort by
0
Petar Kirov
Telerik team
answered on 25 Mar 2013, 03:30 PM
Hi Paulo,

The ASP.NET RadChart uses the OADate format to visualize DateTime data. This means that in order to set a manual X axis range, you will need to convert DateTime values to OADate first: 
double startDateInOA = new DateTime(2013, 1, 1).ToOADate();
double endDateInOA = new DateTime(2013, 5, 1).ToOADate();
double step = 1; // one day in OADate format
  
radChart.PlotArea.XAxis.AutoScale = false;
radChart.PlotArea.XAxis.AddRange(startDateInOA, endDateInOA, step);

Additionally to make the RadChart visualize the X axis labels in DateTime format, you can set the Value format of the axis to one of the DateTime options: 
radChart.PlotArea.YAxis.Appearance.ValueFormat =
    Telerik.Charting.Styles.ChartValueFormat.ShortDate;

By default the RadChart's axes are zero based. This means when AutoScale is true, the first date displayed will be 0.0 which in OADate format is 30 Dec 1899. To change that, you can set radChart.PlotArea.XAxis.IsZeroBased to false.

I hope this helps.

Regards,
Petar Kirov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
General Discussions
Asked by
Paulo
Top achievements
Rank 1
Answers by
Petar Kirov
Telerik team
Share this question
or