maui-devexpress-dot-maui-dot-charts-dot-legend-f1473834.md
Gets or sets the horizontal position of the legend relative to the chart diagram. This is a bindable property.
Namespace : DevExpress.Maui.Charts
Assembly : DevExpress.Maui.Charts.dll
NuGet Package : DevExpress.Maui.Charts
public LegendHorizontalPosition HorizontalPosition { get; set; }
| Type | Default | Description |
|---|---|---|
| LegendHorizontalPosition | Center |
A LegendHorizontalPosition enumeration value that specifies the legend’s horizontal position.
|
Available values:
| Name | Description |
|---|---|
| Center |
The legend is centered horizontally inside the chart diagram.
| | Left |
The legend is positioned inside the chart diagram and aligned to the left side.
| | LeftOutside |
The legend is positioned to the left of the chart diagram.
| | Right |
The legend is positioned inside the chart diagram and aligned to the right side.
| | RightOutside |
The legend is positioned to the right of the chart diagram.
|
Use the HorizontalPosition property to specify the horizontal alignment of the legend. You can place it on the right or left side of the chart, inside or outside the diagram.
To specify the vertical position of the legend, use the VerticalPosition property.
This example shows how to add a legend to a pie chart and adjust the legend settings.
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:
Set the Legend.Style property to a LegendStyle object and specify the following properties of this object to configure the legend appearance:
To exclude points of the chart’s first series from the legend, set the VisibleInLegend property of this series to false.
<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>
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
}
}
};
See Also