X-Axis DateTime Column Exception

Thread is closed for posting
4 posts, 0 answers
  1. Sarah
    Sarah avatar
    19 posts
    Member since:
    Mar 2009

    Posted 14 Sep 2009 Link to this post

    I'm trying to databind a datatables DATETIME column to the  X-Axis Labels from code behind but I keeping getting this error.
    Unable to cast object of type 'System.DateTime' to type 'System.String'.

    From the DATETIME, I only want to use the month and year.  Any ideas. Thanks in advance
  2. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 14 Sep 2009 Link to this post

    You cannot assign a DateTime to the X-Axis since the axis of a RadChart can only take values of the type double. However, using the ToOADate() function you can convert your DateTimes to doubles. Also note that you will have to set your range from a start date to and end date using the same function in order for the RadChart to be able to display your data. Look at the following Numerical Axis demo.
  3. Sarah
    Sarah avatar
    19 posts
    Member since:
    Mar 2009

    Posted 14 Sep 2009 Link to this post

    Thanks for the reply.  I haven't tried out the example yet but is there a way on item databound, i can just set the x axis label?
  4. Schlurk
    Schlurk avatar
    812 posts
    Member since:
    May 2009

    Posted 15 Sep 2009 Link to this post

    You can set a label, however, you still need some form of numerical representation of the data and if that data is outside of the range of your x-axis everything might come up skewed. This example shows how to set the labels programmatically and then you just have to capture the event (don't remember it off the top of my head and can't find it right now). You could do RadChart1_PreRender(object sender, EventArgs e) which lets you fool around with the RadChart right before the image is rendered.
Back to Top