Chart Legend

The Legend feature of the RadChart makes it easy for you to provide description regarding the series which are visualized within the control.

To add the legend feature in your application, you need to initialize a new object of type RadLegend.

<telerik:RadPieChart x:Name="pieChart" HeightRequest="300">
    <telerik:RadCartesianChart.BindingContext>
        <local:ViewModel />
    </telerik:RadCartesianChart.BindingContext>
    <telerik:RadPieChart.Series>
        <telerik:PieSeries DisplayName="Value" LegendTitleBinding="Category" ItemsSource="{Binding Data1}" ValueBinding="Value"/>
    </telerik:RadPieChart.Series>
</telerik:RadPieChart>
<telerik:RadLegend HeightRequest="200" 
                   LegendItemFontColor="DarkGreen"
                   LegendItemFontSize="20"
                   LegendProvider="{x:Reference Name=pieChart}"/>

The following image shows the RadLegend in combination with the Pie Chart.

Pie Chart legend

Properties

As shown in the previous image, each item within the RadLegend represents a specific series. The most important property which you need to set is the LegendProvider. It will point to the chart object whose series will be included in the legend.

The following list summarizes the most important properties of the RadLegend control. In brackets is commented the type of the property:

  • LegendProvider (RadChartBase)—The Chart control whose series will be described in the legend.
  • LegendItemFontSize (double)—The size of the item's title text.
  • LegendItemFontColor (Color)—The color of the item's title text.
  • LegendItemIconSize (Size)—The size of the title icons.
  • Orientation (LegndOrientation)—Sets the orientation of the legend. Can be Horizontal or Vertical.

RadLegend can be used in combination with RadCartesianChart as well.

The following example demonstrates how to define some of the most important Chart legend properties.

<telerik:RadCartesianChart x:Name="chart" HeightRequest="300">
    <telerik:RadCartesianChart.BindingContext>
        <local:ViewModel />
    </telerik:RadCartesianChart.BindingContext>
    <telerik:RadCartesianChart.HorizontalAxis>
        <telerik:CategoricalAxis />
    </telerik:RadCartesianChart.HorizontalAxis>
    <telerik:RadCartesianChart.VerticalAxis>
        <telerik:NumericalAxis />
    </telerik:RadCartesianChart.VerticalAxis>
    <telerik:RadCartesianChart.Series>
        <telerik:LineSeries CategoryBinding="Category"
                            ValueBinding="Value" 
                            DisplayName=" Data1"
                            ItemsSource="{Binding Data1}" />
        <telerik:LineSeries CategoryBinding="Category" 
                            ValueBinding="Value" 
                            DisplayName=" Data2"
                            ItemsSource="{Binding Data2}" />
        <telerik:LineSeries CategoryBinding="Category" 
                            ValueBinding="Value" 
                            DisplayName=" Data3"
                            ItemsSource="{Binding Data3}" />
    </telerik:RadCartesianChart.Series>
</telerik:RadCartesianChart>
<telerik:RadLegend LegendProvider="{x:Reference Name=chart}" 
                   LegendItemFontColor="DarkGreen"
                   HeightRequest="200"/>

The following image shows the RadLegend control in combination with a Cartesian Chart.

Cartesian Chart legend

Legend Title Binding

The LegendTitleBinding is a property which can be set specifically for the Pie Series. It points to the property of the data item which will be used as a title in the legend. For all other series, the DisplayName property will be used instead.

<telerik:RadPieChart.Series>
    <telerik:PieSeries DisplayName="Value" LegendTitleBinding="Category" ItemsSource="{Binding Data1}" ValueBinding="Value"/>
</telerik:RadPieChart.Series>

See Also

In this article
Not finding the help you need?