ItemLabel and ItemTooltip Formatting

2 posts, 0 answers
  1. Petr
    Petr avatar
    8 posts
    Member since:
    Aug 2010

    Posted 11 Mar 2011 Link to this post

    Hi there,

    I'm having some issues with basic number formatting in chart item labels and tooltips. For example, in the following code, I would expect the values in labels/tooltips to have 2 decimal places:

    public partial class MainPage : UserControl
        public MainPage()
            SeriesMapping sm = new SeriesMapping() { SeriesDefinition = new BarSeriesDefinition() };
            sm.ItemMappings.Add(new ItemMapping("X", DataPointMember.XValue));
            sm.ItemMappings.Add(new ItemMapping("Y", DataPointMember.YValue));
            sm.ItemMappings.Add(new ItemMapping("Y", DataPointMember.Label));
            sm.ItemMappings.Add(new ItemMapping("Y", DataPointMember.Tooltip));
            sm.SeriesDefinition.ShowItemLabels = true;
            sm.SeriesDefinition.ItemLabelFormat = "0.00";
            sm.SeriesDefinition.ShowItemToolTips = true;
            sm.SeriesDefinition.ItemToolTipFormat = "0.00";
            List<Data> data = new List<Data>();
            Random r = new Random();
            for (int i = 0; i < 12; i++)
                data.Add(new Data()
                    X = i,
                    Y = r.NextDouble() * 100
            radChart1.ItemsSource = data;
    public class Data
        public double X { get; set; }
        public double Y { get; set; }

    Unfortunately, that doesn't seem to work. Am I missing something here? I'm working with version 2010.3.1110.1040.

    Thank you,
  2. Missing user
    Missing user avatar

    Posted 15 Mar 2011 Link to this post

    Hi Petr,

    In order to use the RadChart specific format mechanism,
    you need to specify the token and the expression in a curly braces:
    seriesMapping.SeriesDefinition.ItemLabelFormat = "#Y{0.00}";
    seriesMapping.SeriesDefinition.ItemToolTipFormat = "#Y{0.00}";

    In this case you don't need to map a value for DataPointMember.Label and DataPointMember.Tooltip because it will override the formatted value. Another approach to display formatted text is to map it already formatted. For example:
    seriesMapping.ItemMappings.Add(new ItemMapping("YValFormatted", DataPointMember.Label));
    seriesMapping.ItemMappings.Add(new ItemMapping("YValFormatted", DataPointMember.Tooltip));

    I hope this helps.

    Best wishes,
    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!
Back to Top