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

ItemLabel and ItemTooltip Formatting

1 Answer 36 Views
This is a migrated thread and some comments may be shown as answers.
Top achievements
Rank 1
Petr asked on 11 Mar 2011, 06:18 AM
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,

1 Answer, 1 is accepted

Sort by
Missing User
answered on 15 Mar 2011, 04:09 PM
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!
Asked by
Top achievements
Rank 1
Answers by
Missing User
Share this question