Using Dates for X Values

Thread is closed for posting
2 posts, 0 answers
  1. Aaron
    Aaron avatar
    38 posts
    Member since:
    Apr 2008

    Posted 03 Aug 2010 Link to this post

    It doesn't seem like you can use dates for X values when adding data to series programmatically.  Is that true?

    Thanks.
  2. Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 05 Aug 2010 Link to this post

    Hello Aaron,

    We would suggest you to review this online example here that demonstrates how you can display DateTime data on the numerical axes of RadChart -- the key is to use the DateTime.ToOADate() method in order to convert the DateTime data to double values as the numerical axes work only with numeric types.

    Here is a sample code snippet as well:
    RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 340;
    RadChart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.ShortDate;
    RadChart1.PlotArea.XAxis.AutoScale = false;
    RadChart1.PlotArea.XAxis.AddRange(DateTime.Today.ToOADate(), DateTime.Today.AddDays(4).ToOADate(), 1);
     
    ChartSeries series = new ChartSeries();
    series.AddItem(new ChartSeriesItem(DateTime.Today.ToOADate(), 200));
    series.AddItem(new ChartSeriesItem(DateTime.Today.AddDays(1).ToOADate(), 350));
    series.AddItem(new ChartSeriesItem(DateTime.Today.AddDays(2).ToOADate(), 100));
    series.AddItem(new ChartSeriesItem(DateTime.Today.AddDays(3).ToOADate(), 500));
    series.AddItem(new ChartSeriesItem(DateTime.Today.AddDays(4).ToOADate(), 600));
     
    RadChart1.Series.Add(series);

    Hope this helps.


    Regards,
    Freddie
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Back to Top