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

OADate support in Tooltips

2 Answers 98 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Hıncal
Top achievements
Rank 1
Hıncal asked on 12 Oct 2010, 02:56 PM
Hi all,

I'm trying to set RadChart's values from OADate to formatted datetime string. It's ok for x-axis value but when I try to set tooltip as formatted datetime string it's confusing.
Anyway you may see a screenShot about this issue at "tooltip.png" file.
And my whole code is below
using System;
using System.Collections.Generic;
using System.Windows.Controls;
using Telerik.Windows.Controls.Charting;
 
namespace TelerikSL4
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();
            var lst = new List<Values>();
            Random rand = new Random();
            for (int i = 0; i < 1000; i++)
                lst.Add(new Values { date = DateTime.Now.AddDays(i).ToOADate(), value = rand.Next(10, 100) });
 
            radChart1.DefaultView.ChartArea.AxisX.IsDateTime = true;
            radChart1.DefaultView.ChartArea.AxisX.DefaultLabelFormat = "dd/MM HH:mm";
            radChart1.DefaultView.ChartArea.AxisX.StepLabelLevelCount = 2;
            radChart1.DefaultView.ChartArea.ZoomScrollSettingsX.ScrollMode = ScrollMode.ScrollAndZoom;
            radChart1.DefaultView.ChartArea.ZoomScrollSettingsY.ScrollMode = ScrollMode.ScrollAndZoom;
 
            SeriesMapping seriesMapping = new SeriesMapping();
            seriesMapping.SeriesDefinition = new LineSeriesDefinition();
 
            seriesMapping.SeriesDefinition.ShowItemLabels = false;
            seriesMapping.SeriesDefinition.ShowItemToolTips = true;
            seriesMapping.SeriesDefinition.LegendDisplayMode = LegendDisplayMode.SeriesLabel;
            seriesMapping.LegendLabel = "Telerik";
            seriesMapping.SeriesDefinition.ItemToolTipFormat = seriesMapping.LegendLabel + "\n#X{dd.MM.yyyy HH:mm}\n#Y";
 
            seriesMapping.ItemMappings.Add(new ItemMapping("date", DataPointMember.XValue));
            seriesMapping.ItemMappings.Add(new ItemMapping("value", DataPointMember.YValue));
 
            radChart1.SeriesMappings.Add(seriesMapping);
 
            radChart1.ItemsSource = lst;
        }
 
        public class Values
        {
            public double date { get; set; }
            public double value { get; set; }
        }
    }
}


Anyone knows how to deal with this issue?
And finally I have to use OADate ;o))

2 Answers, 1 is accepted

Sort by
0
Accepted
Evgeni "Zammy" Petrov
Telerik team
answered on 15 Oct 2010, 07:20 AM
Hello Hıncal,

Thank you for contacting us with this issue.

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.First one works perfectly for your current case and it is the simpler one.

radChart1.ItemDataBound += new EventHandler<ChartItemDataBoundEventArgs>(radChart1_ItemDataBound);
 
void radChart1_ItemDataBound(object sender, ChartItemDataBoundEventArgs e)
{
   e.DataPoint.IsDateTime = true;
}
There is an event when each item is databound, where you can modify anything on a DataPoint, in our case we just set the IsDateTime property on true making sure that the value is take for DateTime.

2.The second one is more explicit but if you ever need to extend the tool-tip it will be an easier job than using the format expressions we offer.
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 HH:mm} \n {1}", DateTime.FromOADate(value), e.DataPoint.YValue);
}

Let me know how this works for you.

All the best,
Evgeni "Zammy" Petrov
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Hıncal
Top achievements
Rank 1
answered on 19 Oct 2010, 02:57 PM
Hi Evgeni,

I used your second suggestion and it works perfectly. Thank you for your responce.

See you.
Tags
Chart
Asked by
Hıncal
Top achievements
Rank 1
Answers by
Evgeni "Zammy" Petrov
Telerik team
Hıncal
Top achievements
Rank 1
Share this question
or