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

Axis X by month

2 Answers 103 Views
Chart (Obsolete)
This is a migrated thread and some comments may be shown as answers.
Najid Hanif
Top achievements
Rank 2
Najid Hanif asked on 01 Aug 2011, 10:24 PM
This seems like it should be really easy and maybe I am just missing something obvious.

I have a simple line chart with 2 lines, its databound.
Y axis is numbers
X axis are dates , last 12 months

It just shows numbers for each date, ie; 1 ,2 , 3 , 4 ..... 11, 12

I want the X axis label to show as dates but I can't figure out how to do it. Using the Chart wizard on the data tab if I set X-Axis to my date column the wizard just disappears before I even click OK.  I have tried a few other ways and I get errors like: Unable to cast object of type 'System.DateTime' to type 'System.String'.

ideas?

thanks





2 Answers, 1 is accepted

Sort by
0
Accepted
Yavor
Telerik team
answered on 04 Aug 2011, 04:48 PM
Hello Najid Hanif,

You can format the DateTime objects as dates by using ValueFormat on the AxisX like this:

<PlotArea>
    <XAxis>
        <Appearance ValueFormat="ShortDate">
            <LabelAppearance RotationAngle="45" />
        </Appearance>
    </XAxis>
</PlotArea>

I have attached a small demo application that demonstrates a chart bound to a list of objects.

Some general notes:
- RadChart does not support directly DateTime values. It supports the OLE Automation date equivalent (obtained through DateTime.ToOADate() method).
- XAxis - it is numeric and by default starts from 0, so you must set IsZeroBased to false in order to show only the period of time you are interested in and not starting from 0 (which is 31/12/1899 in OLE Automation date).
- Finally how to achieve this with SqlDataSource (if necessary) -- here is an example of a query, which converts DateTime values to double: "SELECT [Size], CAST([Date] AS FLOAT) + 2 as float_date FROM [Table_1]". With this query, you will need to set the DataXColumn property to "float_date".

Hope this helps!


Best wishes,
Yavor Ivanov
the Telerik team

Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.

0
Najid Hanif
Top achievements
Rank 2
answered on 04 Aug 2011, 08:21 PM
Thanks! This is what I needed to know. CAST'ing the DATE in the Query was the trick.
Tags
Chart (Obsolete)
Asked by
Najid Hanif
Top achievements
Rank 2
Answers by
Yavor
Telerik team
Najid Hanif
Top achievements
Rank 2
Share this question
or