Back to Devexpress

Legend Class

maui-devexpress-dot-maui-dot-charts-8fd8860e.md

latest5.1 KB
Original Source

Legend Class

Stores chart legend settings.

Namespace : DevExpress.Maui.Charts

Assembly : DevExpress.Maui.Charts.dll

NuGet Package : DevExpress.Maui.Charts

Declaration

csharp
public class Legend :
    StyledElement

The following members return Legend objects:

Remarks

Legend is an explanatory component that accompanies a chart diagram and identifies its most important visual elements: series, series points, constant lines and strips.

The Legend class properties define chart legend settings:

  • Orientation - Specifies whether legend items are positioned vertically from the top to the bottom or horizontally from the left to the right.
  • HorizontalPosition, VerticalPosition - Control the legend position within a chart.
  • Style - Provides access to legend appearance settings.
  • Visible - Allows you to show or hide a legend.

To configure a chart legend, assign a Legend object with the specified properties to the chart’s Legend property.

Example

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.

xaml
<dxc:PieChartView x:Name="chartView">
    <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,150,10,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>
csharp
using Microsoft.Maui.Graphics;
using DevExpress.Maui.Charts;
// ...

chartView.Legend = new Legend()
{
    Orientation = LegendOrientation.LeftToRight,
    VerticalPosition = LegendVerticalPosition.TopOutside,
    HorizontalPosition = LegendHorizontalPosition.Center,
    Style = new LegendStyle() {
        BorderColor = Color.LightGray,
        BorderThickness = 3,
        BackgroundColor = Color.Gray,
        MarkerSize = 30,
        TextIndent = 10,
        ItemsHorizontalIndent = 50,
        Padding = new Padding(150, 150, 10, 10),
        TextStyle = new TextStyle() {
            Color = Color.White,
            Size = 24
        }
    }
};

Implements

IElementController

INotifyPropertyChanged

Inheritance

System.Object BindableObject Element ChartElementBase ChartElement StyledElement Legend

Extension Methods

Yield<Legend>()

YieldIfNotNull<Legend>()

See Also

Legend Members

DevExpress.Maui.Charts Namespace