OADate support in Tooltips

3 posts, 1 answers
  1. Hıncal
    Hıncal avatar
    9 posts
    Member since:
    Aug 2010

    Posted 12 Oct 2010 Link to this post

    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. Answer
    Evgeni "Zammy" Petrov
    Admin
    Evgeni "Zammy" Petrov avatar
    168 posts

    Posted 15 Oct 2010 Link to this post

    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
  3. Hıncal
    Hıncal avatar
    9 posts
    Member since:
    Aug 2010

    Posted 19 Oct 2010 Link to this post

    Hi Evgeni,

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

    See you.
Back to Top