ChartBaseView.Legend Property

Gets or sets the chart legend.

Namespace: DevExpress.XamarinForms.Charts

Assembly: DevExpress.XamarinForms.Charts.dll

Declaration

public Legend Legend { get; set; }

Property Value

Type Description
Legend

The Legend object that stores chart legend settings.

Remarks

A legend is a chart element that identifies series, series points, constant lines and strips displayed on the chart diagram.

Chart Legend Elements

A legend content depends on the chart type:

To show a constant line or strip in a legend, set the ConstantLineBase.VisibleInLegend or StripBase.VisibleInLegend property to true. To specify a constant line or strip description to be shown in the legend, use the ConstantLineBase.LegendText or StripBase.LegendText property.

To add a legend to a chart, assign a Legend object with the specified legend settings to the ChartBaseView.Legend property.

Legend Layout and Position

Legend items can be displayed in a column or row. Use the Legend.Orientation property to control the legend layout.

Property Value

Result

Legend.Orientation = TopToBottom

Legend Orientation TopToBottom

Legend.Orientation = LeftToRight

Legend Orientation LeftToRight

You can modify the vertical and horizontal position of a legend, and place a legend inside or outside a chart diagram. To set the legend position, use the Legend.VerticalPosition and Legend.HorizontalPosition properties. The following table shows some examples of how these properties work.

Property Values

Result

VerticalPosition = Top

HorizontalPosition = Right

Legend Position Top Right

VerticalPosition = TopOutside

HorizontalPosition = RightOutside

Legend Position TopOutside RightOutside

VerticalPosition = BottomOutside

HorizontalPosition = Center

Legend Position BottomOutside Center

Legend Appearance

To customize the legend appearance, assign the LegendStyle object to the Legend.Style property. Use the LegendStyle object's properties to change the legend background color and border, size of legend markers, item text color and size, and distances between legend elements (between items, between an item marker and text, between legend edges and items, between legend edges and chart border).

Legend Style

Examples

This example shows how to add a legend to a pie chart and adjust the legend settings.

  1. To add a legend to the chart, assign a Legend object to the PieChartView.Legend property and use the following properties of this object to specify the legend orientation and position:

  2. Set the Legend.Style property to a LegendStyle object and specify the following properties of this object to configure the legend appearance:

  3. To exclude points of the chart's first series from the legend, set the VisibleInLegend property of this series to false.

Chart Legend

<dxc:PieChartView>
    <dxc:PieChartView.Series>
        <dxc:DonutSeries Data="{Binding SecuritiesByTypes}" VisibleInLegend="False"/>
        <dxc:DonutSeries Data="{Binding SecuritiesByRisk}"/>
    </dxc:PieChartView.Series>
    <dxc:PieChartView.Legend>
        <dxc:Legend Orientation="LeftToRight"
                    VerticalPosition="TopOutside"
                    HorizontalPosition="Center">
            <dxc:Legend.Style>
                <dxc:LegendStyle BorderColor="LightGray" BorderThickness="3"
                                 BackgroundColor="Gray"
                                 MarkerSize="30" TextIndent="10"
                                 ItemsHorizontalIndent="50"
                                 Padding="150,10,150,10">
                    <dxc:LegendStyle.TextStyle>
                        <dxc:TextStyle Color="White" Size="24"/>
                    </dxc:LegendStyle.TextStyle>
                </dxc:LegendStyle>
            </dxc:Legend.Style>
        </dxc:Legend>
    </dxc:PieChartView.Legend>
</dxc:PieChartView>
See Also