DataFormatString of Datetime

7 posts, 0 answers
  1. Ron
    Ron avatar
    86 posts
    Member since:
    Sep 2009

    Posted 18 Jun 2012 Link to this post

    Hello,

    Is there a way to get the LabelAppearance.DataformatString = "{0:d}" to work?  No matter which way I try to format this using, including trying  {0:MM/dd/yyyy}, I cannot get the string to format correctly and remove the time component of the data returned.  I have seen in many searches on the internet that HTMLEncode should be set to false to resolve this, but this is not something that I can set with the control.

    Thanks,
    Ron
  2. Marin Bratanov
    Admin
    Marin Bratanov avatar
    3595 posts

    Posted 20 Jun 2012 Link to this post

    Hi Ron,

    I am sorry to say that for the time being date format strings are not supported. In case you need to show dates on the items for the X-axis I can suggest that you create them programmatically in the code-behind by looping through the datasource and creating items, then using one of the toString() overrides to have a string with the desired format that you can use either in the AxisItem() constructor, or set to the LabelText property of the AxisItem.


    All the best,
    Marin Bratanov
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Brian
    Brian avatar
    14 posts
    Member since:
    Sep 2012

    Posted 25 Oct 2012 Link to this post

    I am running into this same problem - is there any chance you can show a bit of sample code for building these items programatically and filling the Line chart this way as opposed to the simple DataSource / DataBind method?  Having the time displayed in my X Axis is not working out very well at all.

    TIA
  5. DuelingCats
    DuelingCats avatar
    49 posts
    Member since:
    Jul 2012

    Posted 25 Oct 2012 Link to this post

    Ron, this may help you out. I use this method to format my date strings in the code behind and then data bind it.

    var historyData = from data in context.MyDataSet
      orderby data.Date descending
      select new
      {
          Date = data.Date.ToString("MMM yy"),
          Score = data.Score
      };
       
    HistoryChart.DataSource = historyData.ToList();

    <telerik:RadHtmlChart ID="HistoryChart" runat="server" Height="250px" Width="600px">
    <PlotArea>
        <Series>
            <telerik:LineSeries Name="Score" DataFieldY="Score">
            </telerik:LineSeries>
        </Series>
        <XAxis DataLabelsField="Date">
            <TitleAppearance Text="Month" />
        </XAxis>
        <YAxis Step="20" MinValue="0" MaxValue="110">
        </YAxis>
    </PlotArea>
    </telerik:RadHtmlChart>
  6. J2K
    J2K avatar
    33 posts
    Member since:
    Sep 2005

    Posted 22 Feb 2013 Link to this post

    Ummmm ..... the X axis has a property called "DataFormatString", but after wasting the past 3 hours trying all sorts of stuff, only to learn that the DataFormatString means "DataFormatStringProvidingTheDataIsNOTaDATE" ..... is that what Telerik is saying?  Loop through the data to set values?  Kind of weak.  At least don't waste my time by actually calling it what it is, ok, for example, the property name could be "Don'tWasteYourTimeTryingToFormataDateHere".
  7. Danail Vasilev
    Admin
    Danail Vasilev avatar
    1490 posts

    Posted 27 Feb 2013 Link to this post

    Hello Mark,

    Thank you for sharing your feedback with us.

    You can have a look at this help article which lists the values the DataFormatString property exposes (i.e. date format is not included here). As my colleague has already mentioned in his post, date time objects are not supported by the RadHtmlChart yet. This is a limitation of the control and our online documentation can, indeed, be improved to expose it better.

    Nevertheless, our developers are currently working on handling DateTime objects as a datasource to the RadHtmlChart. However, I cannot guarantee any time bounds for its implementation due to the:
    • Specifics of this feature request - .NET DateTime objects are different than JavaScript Date objects which requires additional conversion
    • The control should not modify the datasource the developer passes. We are still trying to find a way around this obvious contradiction of concepts

    Regarding the name of the property, note that it is called DataFormatString and not a DateFormatString. You can also have a look at this help article that shows an example on how to create a custom conversion of the DateTime objects and populate them on the XAxis labels.

    All the best,
    Danail Vasilev
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
  8. msigman
    msigman avatar
    141 posts
    Member since:
    Apr 2008

    Posted 18 Feb 2014 in reply to Danail Vasilev Link to this post

    For anyone searching for and finding this post, since Q2 2013 the RadHtmlChart can be databound to DateTime objects, so that XAxis Labels, Series Labels and ToolTips can be formatted to the desired date format. More information on formatting dates is available in Date Axis article: http://www.telerik.com/help/aspnet-ajax/htmlchart-date-axis.html.
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017