Dates as XAxis Labels

Thread is closed for posting
2 posts, 0 answers
  1. Nick Jones
    Nick Jones avatar
    18 posts
    Member since:
    Jun 2009

    Posted 18 Feb 2010 Link to this post

    I hope someone can help I'm pulling my hairout here.  I know there are a few threads already on this, but none of them are helping me.

    I have two columns in a datatable.  OrderDate and OrderTotal.

    I've got this code.

    RadChart1.PlotArea.XAxis.Appearance.LabelAppearance.RotationAngle = 45

    RadChart1.PlotArea.XAxis.Appearance.ValueFormat = Telerik.Charting.Styles.ChartValueFormat.LongDate


    RadChart1.PlotArea.XAxis.DataLabelsColumn = "OrderDate"


    RadChart1.DataSource = dtOrders


    You've already probably guessed what my question is.  This errors becuase I believe the OrderDate is not in the correct format and I need to us toAODate() in order to make this work.  Great, how?  Do I have to convert the data in the datatable with this function? How do you use it?  I've looked at the microsoft page, it didn't shed any light for me.

    I understand that;

    Dim SomeDateAsADouble as Double
    DatetoConvert as Date = Today()

    SomeDateAsADouble  = DatetoConvert.ToAODate()

    How does this help with the above problem?

    RadChart1.PlotArea.XAxis.DataLabelsColumn = "OrderDate".ToAODate()   ;This won't work

    Please can someone help me, and anyone after me with an explained solution.  I really would appreciate it.

  2. Ves
    Ves avatar
    2926 posts

    Posted 19 Feb 2010 Link to this post

    Hello Nick Jones,

    You can find below the answer I provided in the support ticket you started:

    Please, find attached a small example showing two possible ways to display DateTime values in RadChart.
    1. Using the OLE Automation DateTime equivalent -- in this case the underlying data should have the DateTime values already converted to double through ToOADate method. You need to set the ChartSeriesItem's XValue property with that value (that is -- the position along the X axis). In databound scenarios this is achieved by setting the DataXColumn property of the ChartSeries. Then you can set the XAxis.Appearance.ValueFormat property as per your requirements (there's an addition to this -- XAxis.Appearance.CustomFormat, in case the pre-defined ones are not suitable). Finally, as the OLE Automation date equivalents for these days are numbers close to 40000 you will need to set the XAxis.IsZeroBased to false.
    2. Using strings -- in this case the underlying data should be already converted to string values. Then you can set the XAxis.DataLabelsColumn property to the name of the column, holding these strings. You cannot apply futher formatting here -- the strings are directly sent to the axis items.
    You will spot the difference between those approaches: With the first one -- if there are gaps in the DateTime values they will be preserved in the graph as the values are numeric. With the second one RadChart will simply put the strings to axis item labels, and the items in the graph will appear at equal intervals.

    One final note on approach one -- you can use the following line to extract DateTime values converted to OLE Automation date directly from SQL:

    "SELECT [Value], CAST([Date] AS FLOAT) + 2 as float_date FROM [Table_1]"

    Hope this helps.

    Best regards,
    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