Axis X by month

Thread is closed for posting
3 posts, 1 answers
  1. Najid Hanif
    Najid Hanif avatar
    92 posts
    Member since:
    Jul 2011

    Posted 01 Aug 2011 Link to this post

    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'.



  2. Answer
    Yavor avatar
    401 posts

    Posted 04 Aug 2011 Link to this post

    Hello Najid Hanif,

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

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

    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.

  3. Najid Hanif
    Najid Hanif avatar
    92 posts
    Member since:
    Jul 2011

    Posted 04 Aug 2011 Link to this post

    Thanks! This is what I needed to know. CAST'ing the DATE in the Query was the trick.
Back to Top