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

ItemToolTip Problem with DateFormat

5 Answers 85 Views
Chart
This is a migrated thread and some comments may be shown as answers.
marcos
Top achievements
Rank 1
marcos asked on 11 Mar 2011, 09:49 AM
Hey,

I can't display the correct x-axis date value in the itemtooltip.
Here are the interesting facts for you...

I have a chart with thousands of points so i use:
<telerik:AxisX AutoRange="True"...


That's why in my ItemToolTip the first value works and the last not (because of this link this link):
<telerik:LineSeriesDefinition ItemToolTipFormat="#X --> #DATAITEM.Date or #DATAITEM.Date{MM/dd/yyyy}"...


But I can't use #X because it's from double type and the result is something like "42k" - but not a date!

What kind of solution you can offer for my problem? Is there a posibility to convert the double to string inside xaml?
(i can't use codebehind...)

5 Answers, 1 is accepted

Sort by
0
Evgenia
Telerik team
answered on 16 Mar 2011, 09:41 AM
Hi marcos,

To convert the double values to DateTime so that you will be able to set custom formatting there are two approaches you may choose from:
1. Convert the values during binding - to achieve this you must create a class that implements the IValueConverter interface, which includes the Convert and ConvertBack methods as shown in this article.

2. Subscribe to ItemDataBound event of the Chart and convert the current value to DateTime like this: 
DateTime MyDate = DateTime.FromOADate(MyOADate);
Then apply custom format string for it.

Best wishes,
Evgenia
the Telerik team
Registration for Q1 2011 What’s New Webinar Week is now open. Mark your calendar for the week starting March 21st and book your seat for a walk through all the exciting stuff we ship with the new release!
0
marcos
Top achievements
Rank 1
answered on 16 Mar 2011, 10:51 AM
Hey,
please taka a look to my xaml which is here:
http://www.telerik.com/community/forums/wpf/chart/itemtooltip-problem-with-dataformat.aspx
(I realized to late that I've posted in WPF and not Silverlight...)

Can you explain where exactly I have to change???

P.S.  I attach a screenshot of the result
ItemToolTipFormat="Values #Y - #X - #X{dd.MM.yyyy} "
0
Evgenia
Telerik team
answered on 18 Mar 2011, 09:18 AM
Hi marcos,

The problem appears because the value bound to XValue on the DataPoint is not DateTime.
The chart cannot implicitly infer if the double is just double or OAData.

I can offer you two solutions:

1. Subscribe to ItemDataBound event of the Chart and set each DataPoint's IsDateTime property to true which ensures that the XValue of the DataPoint will be DateTime. 

radChart1.ItemDataBound += new EventHandler<ChartItemDataBoundEventArgs>(radChart1_ItemDataBound);
   
void radChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
{
   e.DataPoint.IsDateTime = true;
}

2. The second one is to subscribe to ItemTooltipOpening event of the ChartArea and set custom format string for the DateTime converted XValue:

radChart1.DefaultView.ChartArea.ItemToolTipOpening += new ItemToolTipEventHandler(ChartArea_ItemToolTipOpening);
   
void ChartArea_ItemToolTipOpening(ItemToolTip2D tooltip, ItemToolTipEventArgs e)
{
double value = (double)e.DataPoint.XValue;
    tooltip.Content = e.DataSeries.LegendLabel + 
string.Format("{0:dd.MM.yyyy} \n {1}", DateTime.FromOADate(value), e.DataPoint.YValue);
}

Let me know how this works for you.

All the best,
Evgenia Milcheva
the Telerik team

0
marcos
Top achievements
Rank 1
answered on 18 Mar 2011, 10:36 AM
Hi,
I tried the first solution and it works perfectly. So thanks a lot...

But if I understand it correct, the problem ist the Double Format of my XAxisValue. Well, if I set the XValue directly to a DateTimeProperty I get an unhandled Error in my Silverlight Application (Code 4004, somethign with Average and Type System.Linq.Enumerable...)

Is there a way to achieve a well formated output in the graph and the tooltip too only by modifying the xaml without codebehind???
What about different properties for XCat and XValue?
Available are these properties:
1) DATE_DOUBLE (Double)
2) DATE_STRING (String)
3) DATE (DateTime)

I am looking forward to hearing from you soon.

marcos
0
Evgenia
Telerik team
answered on 23 Mar 2011, 03:38 PM
Hello marcos,

  Before answering your questions let me explain you the way RadChart's XAxis values can be set. As XAxis expects it's items to be of type double you can't directly set DateTime values as XValue. The DateTime values should be converted to their OLE Automation equivalents using theToOADate() method provided by the Framework.
If you want to plot not only values (e.g. number of sales, etc.), but also categories (e.g. months of the year, units, people, etc.) you should use XCategory as it treats the data as a sequence of non-numerical text labels.
To your question:
  1) DATE_DOUBLE (Double) - ItemTooltipFormat can be set as I showed you in my previous post.
  2) DATE_STRING (String) - as if your Date values were represented by XCategory. In this case the ItemTooltipFormat can be set as my co-worker Evgeni suggested in this forum post. Happily to you this suggestion uses XAML only to format the XCategory.
  3) DATE (DateTime) - you should convert the DateTime to OADate() and then set the ItemTooltipFormat as written in 1).

I hope this information helps!

All the best,
Evgenia
the Telerik team
Tags
Chart
Asked by
marcos
Top achievements
Rank 1
Answers by
Evgenia
Telerik team
marcos
Top achievements
Rank 1
Share this question
or