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

DataFormatString of Datetime

6 Answers 496 Views
Chart (HTML5)
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 2
Ron asked on 18 Jun 2012, 06:41 PM
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

6 Answers, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 20 Jun 2012, 02:13 PM
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.
0
Brian
Top achievements
Rank 1
answered on 25 Oct 2012, 03:04 PM
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
0
DuelingCats
Top achievements
Rank 2
answered on 25 Oct 2012, 03:52 PM
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>
0
J2K
Top achievements
Rank 1
answered on 23 Feb 2013, 01:38 AM
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".
0
Danail Vasilev
Telerik team
answered on 27 Feb 2013, 10:53 AM
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.
0
msigman
Top achievements
Rank 2
answered on 18 Feb 2014, 09:13 PM
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.
Tags
Chart (HTML5)
Asked by
Ron
Top achievements
Rank 2
Answers by
Marin Bratanov
Telerik team
Brian
Top achievements
Rank 1
DuelingCats
Top achievements
Rank 2
J2K
Top achievements
Rank 1
Danail Vasilev
Telerik team
msigman
Top achievements
Rank 2
Share this question
or