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

X-Axis DateTime Column Exception

3 Answers 203 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Sarah
Top achievements
Rank 1
Sarah asked on 14 Sep 2009, 07:16 PM
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

3 Answers, 1 is accepted

Sort by
0
Schlurk
Top achievements
Rank 2
answered on 14 Sep 2009, 09:27 PM
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.
0
Sarah
Top achievements
Rank 1
answered on 14 Sep 2009, 10:29 PM
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?
0
Schlurk
Top achievements
Rank 2
answered on 15 Sep 2009, 02:18 PM
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.
Tags
Chart (Obsolete)
Asked by
Sarah
Top achievements
Rank 1
Answers by
Schlurk
Top achievements
Rank 2
Sarah
Top achievements
Rank 1
Share this question
or