# Annotation Labels

The CartesianStrokedAnnotation class provides infrastructure for annotation labels.

> Only the annotations deriving from CartesianStrokedAnnotation ( [CartesianGridLine](https://www.telerik.com/products/wpf/documentation/controls/radchartview/features/annotations/gridline) and [CartesianPlotBand](https://www.telerik.com/products/wpf/documentation/controls/radchartview/features/annotations/plotband) ) have out-of-the-box support for this feature.

## Setting a Label

To show the annotation's label, set its **Label** property.

**Example 1: Setting annotation label**

```XAML
<telerik:RadCartesianChart>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis x:Name="verticalAxis"/>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis/>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.Series>
        <telerik:BarSeries>
            <telerik:BarSeries.DataPoints>
                <telerik:CategoricalDataPoint Category="A" Value="10"/>
                <telerik:CategoricalDataPoint Category="B" Value="12"/>
                <telerik:CategoricalDataPoint Category="C" Value="5"/>
            </telerik:BarSeries.DataPoints>
        </telerik:BarSeries>
    </telerik:RadCartesianChart.Series>
    <telerik:RadCartesianChart.Annotations>
        <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=verticalAxis}" Value="8" Stroke="Green" StrokeThickness="2"
											 Label="Average Value" />
    </telerik:RadCartesianChart.Annotations>
</telerik:RadCartesianChart>
```

> caption Annotation label

![Telerik UI for WPF RadChartView annotation label](https://www.telerik.com/products/wpf/documentation/assets/588cd033f92ac3e3f1ead6008fdfab10/radchartview-annotations-labels-0.png)

## Using Label Definition

The chart annotation labels are adjusted using the **LabelDefinition** property. The property accepts a value of type **ChartAnnotationLabelDefinition** that allows you to style and position the label.

**Example 2: Setting LabelDefinition**

```XAML
<telerik:RadCartesianChart>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis x:Name="verticalAxis1"/>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis/>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.Series>
        <telerik:BarSeries>
            <telerik:BarSeries.DataPoints>
                <telerik:CategoricalDataPoint Category="A" Value="10"/>
                <telerik:CategoricalDataPoint Category="B" Value="12"/>
                <telerik:CategoricalDataPoint Category="C" Value="5"/>
            </telerik:BarSeries.DataPoints>
        </telerik:BarSeries>
    </telerik:RadCartesianChart.Series>
    <telerik:RadCartesianChart.Annotations>
        <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=verticalAxis1}" 
											 Value="8"
											 Stroke="Green" 
											 StrokeThickness="2"
											 Label="AverageValue">
            <telerik:CartesianGridLineAnnotation.LabelDefinition>
                <telerik:ChartAnnotationLabelDefinition Location="Inside" HorizontalAlignment="Center"/>
            </telerik:CartesianGridLineAnnotation.LabelDefinition>
        </telerik:CartesianGridLineAnnotation>
    </telerik:RadCartesianChart.Annotations>
</telerik:RadCartesianChart>
```

> caption Centered label

![Telerik UI for WPF RadChartView centered annotation label](https://www.telerik.com/products/wpf/documentation/assets/5f5ab055612139f3bb486789b865b45b/radchartview-annotations-labels-1.png)

## Label Positioning

Annotations provide a mechanism for label positioning that consists of three layers - primary (via the **Location** property), secondary (via the **HorizontalAlignment/VerticalAlignment** property), and tertiary (via the **HorizontalOffset/ VerticalOffset** property).

* **Location** property: It defines the primary location of the annotation label visual. It allows you to position the label in 5 different positions, as illustrated below.

> caption Locations relative to the annotation's visual

```
![Telerik UI for WPF RadChartView annotation label location options](images/RadChartView-annotations-label-location.png)
```

* **Horizontal / Vertical Alignment** property: In conjunction with Location property, you can use the **HorizontalAlignment** and **VerticalAlignment** properties to further specify the position of the label. Refer to the table below for possible combinations of these properties:

> caption Possible alignment-location combinations

```
![Telerik UI for WPF RadChartView annotation label alignment and location combinations](images/RadChartView-annotations-alignment-location.png)
```

* **Horizontal / Vertical Offset** property: Besides the Location, HorizontalAlignment and Vertical Alignment, you can use the **HorizontalOffset** and **VerticalOffset** properties to specify an offset in pixels. This offset is applied after the aforementioned properties.

**Example 3: Custom positioned label**

```XAML
<telerik:RadCartesianChart>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis x:Name="verticalAxis2"/>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis/>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.Series>
        <telerik:BarSeries>
            <telerik:BarSeries.DataPoints>
                <telerik:CategoricalDataPoint Category="A" Value="10"/>
                <telerik:CategoricalDataPoint Category="B" Value="12"/>
                <telerik:CategoricalDataPoint Category="C" Value="5"/>
            </telerik:BarSeries.DataPoints>
        </telerik:BarSeries>
    </telerik:RadCartesianChart.Series>
    <telerik:RadCartesianChart.Annotations>
        <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=verticalAxis2}" 
											 Value="8"
											 Stroke="Green" 
											 StrokeThickness="2"
											 Label="AverageValue">
            <telerik:CartesianGridLineAnnotation.LabelDefinition>
                <telerik:ChartAnnotationLabelDefinition Location="Top"
														HorizontalAlignment="Center" 
														VerticalOffset="-30"
														HorizontalOffset="100"/>
            </telerik:CartesianGridLineAnnotation.LabelDefinition>
        </telerik:CartesianGridLineAnnotation>
    </telerik:RadCartesianChart.Annotations>
</telerik:RadCartesianChart>
```

> caption Custom positioned label

![Telerik UI for WPF RadChartView annotation label with a custom offset](https://www.telerik.com/products/wpf/documentation/assets/76da76bd57a5ecaf9db739eee5a1f284/radchartview-annotations-labels-2.png)

## Default Visual Style

The default visual element of the label is a native TextBlock. To customize it you can use the **DefaultVisualStyle** property of the ChartAnnotationLabelDefinition.

**Example 4: Setting DefaultVisualStyle**

```XAML
<telerik:RadCartesianChart>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis x:Name="verticalAxis3"/>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis/>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.Series>
        <telerik:BarSeries>
            <telerik:BarSeries.DataPoints>
                <telerik:CategoricalDataPoint Category="A" Value="10"/>
                <telerik:CategoricalDataPoint Category="B" Value="12"/>
                <telerik:CategoricalDataPoint Category="C" Value="5"/>
            </telerik:BarSeries.DataPoints>
        </telerik:BarSeries>
    </telerik:RadCartesianChart.Series>
    <telerik:RadCartesianChart.Annotations>
        <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=verticalAxis3}" 
											 Value="8"
											 Stroke="Green" 
											 StrokeThickness="2"
											 Label="Average Value">
            <telerik:CartesianGridLineAnnotation.LabelDefinition>
                <telerik:ChartAnnotationLabelDefinition Location="Top" HorizontalAlignment="Center">
                    <telerik:ChartAnnotationLabelDefinition.DefaultVisualStyle>
                        <Style TargetType="TextBlock">
                            <Setter Property="Foreground" Value="Purple" />
                            <Setter Property="FontWeight" Value="Bold" />
                        </Style>
                    </telerik:ChartAnnotationLabelDefinition.DefaultVisualStyle>
                </telerik:ChartAnnotationLabelDefinition>
            </telerik:CartesianGridLineAnnotation.LabelDefinition>
        </telerik:CartesianGridLineAnnotation>
    </telerik:RadCartesianChart.Annotations>
</telerik:RadCartesianChart>
```

> caption Customized label style

![Telerik UI for WPF RadChartView annotation label with custom style](https://www.telerik.com/products/wpf/documentation/assets/c4a959d80c9717b56231faba401e8486/radchartview-annotations-labels-3.png)

## Defining a Custom Label Template

To replace the default label visual element with an entirely custom UI you can use the **Template** property of the ChartAnnotationLabelDefinition.

**Example 5: Setting custom label template**

```XAML
<telerik:RadCartesianChart>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:LinearAxis x:Name="verticalAxis4"/>
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis/>
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.Series>
        <telerik:BarSeries>
            <telerik:BarSeries.DataPoints>
                <telerik:CategoricalDataPoint Category="A" Value="10"/>
                <telerik:CategoricalDataPoint Category="B" Value="12"/>
                <telerik:CategoricalDataPoint Category="C" Value="5"/>
            </telerik:BarSeries.DataPoints>
        </telerik:BarSeries>
    </telerik:RadCartesianChart.Series>
    <telerik:RadCartesianChart.Annotations>
        <telerik:CartesianGridLineAnnotation Axis="{Binding ElementName=verticalAxis4}" 
                                             Value="8"
                                             Stroke="Green" 
                                             StrokeThickness="2"
                                             Label="Average Value">
            <telerik:CartesianGridLineAnnotation.LabelDefinition>
                <telerik:ChartAnnotationLabelDefinition Location="Top" HorizontalOffset="5">
                    <telerik:ChartAnnotationLabelDefinition.Template>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <Rectangle Fill="#FFA03B" Width="10" Height="10" />
                                <TextBlock Text="{Binding}" Margin="5 0 0 0" FontStyle="Italic"/>
                            </StackPanel>
                        </DataTemplate>
                    </telerik:ChartAnnotationLabelDefinition.Template>
                </telerik:ChartAnnotationLabelDefinition>
            </telerik:CartesianGridLineAnnotation.LabelDefinition>
        </telerik:CartesianGridLineAnnotation>
    </telerik:RadCartesianChart.Annotations>
</telerik:RadCartesianChart>
```

> caption Customized label template

![Telerik UI for WPF RadChartView annotation with customized label template](https://www.telerik.com/products/wpf/documentation/assets/c5a75338cf4acdc86ee824bd45cdc908/radchartview-annotations-labels-4.png)

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radchartview/getting-started/introduction)
* [Annotations Provider](https://www.telerik.com/products/wpf/documentation/controls/radchartview/features/annotations/annotations-provider)
* [Series Labels](https://www.telerik.com/products/wpf/documentation/controls/radchartview/features/labels/label-definition)
