Telerik UI for Windows Phone by Progress

Label definitions

Every chart series has a convenient API that gives full control over the labels of its data points to the developer. Every chart series object has a LabelDefinitions property. It is a collection of ChartSeriesLabelDefinition objects. Each label definition from the collection will be applied to to each data point. This means that a data point may have multiple labels that display different information for the data point object. All C#/XAML examples below assume that the data points have the following definition:

CopyC#
public class MyClass
{
    public int Value
    {
        get;
        set;
    }

    public string Text
    {
        get;
        set;
    }
}
A label definition has the following properties:
  • Binding

    The Binding property is of type DataPointBinding. It specifies which property of the data point object should be used to obtain a label for the data point.

    CopyXAML
    <telerikChart:ChartSeriesLabelDefinition Binding="Text"/>
  • Format

    The Format property is of type string and is used to apply formatting to the data point label. The format string expected is the same as the format string expected by the string.Format() method in the BCL.

    CopyXAML
    <telerikChart:ChartSeriesLabelDefinition Binding="Text"
                                             Format="some sophisticated way to say display {0}"/>
  • Margin

    Margin is of type Thickness and is used to specify a margin around the data point label. In the pie series, only the Left property of the margin has any effect. It offsets the label away from the center.

  • HorizontalAlignment

    The HorizontalAlignment property specifies the horizontal alignment of the label inside its layout slot. This property has no effect if the data point is in the pie series.

  • VerticalAlignment

    The VerticalAlignment property specifies the vertical alignment of the label inside its layout slot. This property has no effect if the data point is in the pie series.

  • Template

    The Template property is a DataTemplate and can be used to specify a completely custom label visualization. The data context of the Template is a string that is created by the chart with the aid of the Binding and Format properties. In other words, the data context is the formatted string created from the value of the property specified by Binding.

    CopyXAML
    <telerikChart:ChartSeriesLabelDefinition Binding="Text">
        <telerikChart:ChartSeriesLabelDefinition.Template>
            <DataTemplate>
                <Grid Background="HotPink">
                    <TextBlock Text="{Binding}"/>
                </Grid>
            </DataTemplate>
        </telerikChart:ChartSeriesLabelDefinition.Template>
    </telerikChart:ChartSeriesLabelDefinition>
  • TemplateSelector

    The TemplateSelector property is of type DataTemplateSelector and can be used to specify a a custom data template for specific values of the property that a label definition is related to. For example if the label definition is bound to the Value property the template selector can choose completely different data templates for unique values, like a red foreground for values below some threshold and green for values above.

    CopyXAML
    <telerikChart:ChartSeriesLabelDefinition Binding="Text"
                                             TemplateSelector="{StaticResource TemplateSelector}"/>
    CopyXAML
    <Grid.Resources>
        <DataTemplate x:Key="GoodTemplate">
            <TextBlock Foreground="Green"
                       Text="{Binding}"/>
        </DataTemplate>
    
        <DataTemplate x:Key="BadTemplate">
            <TextBlock Foreground="Red"
                       Text="{Binding}"/>
        </DataTemplate>
    
        <local:ThresholdTemplateSelector x:Key="TemplateSelector"
                                         GoodTemplate="{StaticResource GoodTemplate}"
                                         BadTemplate="{StaticResource BadTemplate}"/>
    </Grid.Resources>
    CopyC#
    public class ThresholdTemplateSelector : DataTemplateSelector
    {
        public DataTemplate GoodTemplate
        {
            get;
            set;
        }
    
        public DataTemplate BadTemplate
        {
            get;
            set;
        }
    
        public override System.Windows.DataTemplate SelectTemplate(object item, System.Windows.DependencyObject container)
        {
            DataPoint point = (DataPoint)item;
            MyClass dataItem = (MyClass)point.DataItem;
            if (dataItem.Value < 2)
            {
                return this.BadTemplate;
            }
    
            return this.GoodTemplate;
        }
    }
  • Strategy

    The Strategy property is of type ChartSeriesLabelStrategy. It can be used to completely override all or some visual aspects of the label display logic as well as the label layout.