Skip to main content
A newer version of this page is available. .

Series.Legend Property

Specifies a legend (or its View Model) that contains the series’ legend item.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v19.1.dll

Declaration

public object Legend { get; set; }

Property Value

Type Description
Object

An object of a legend’s View Model class or the Legend object.

Example

This example illustrates how to assign the chart control’s panes, axes, and legends to series:

Binding Sample

Important

The series can use only elements that are defaults (for example, XYDiagram2D.AxisY or stored in element collections (for example, ChartControlBase.Legends). Do not assign new elements to series properties.

<Window x:Class="LegendSample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
        xmlns:viewmodel="clr-namespace:LegendSample.ViewModel"
        mc:Ignorable="d"
        Title="MainWindow" Height="720" Width="1280">
    <Window.DataContext>
        <viewmodel:WeatherViewModel/>
    </Window.DataContext>
    <Window.Resources>
        <Style TargetType="dxc:Range">
            <Setter Property="dxc:AxisY2D.AlwaysShowZeroLevel" 
                    Value="False"/>
        </Style>
        <Style TargetType="dxc:Legend">
            <Setter Property="HorizontalPosition"
                    Value="Left"/>
        </Style>
    </Window.Resources>
    <Grid>
        <dxc:ChartControl DataSource="{Binding WeatherItems}" AutoLayout="False">
            <dxc:ChartControl.Legends>
                <dxc:Legend x:Name="temperatureLegend" 
                            DockTarget="{Binding ElementName=temperaturePane}"/>
                <dxc:Legend x:Name="pressureLegend" 
                            DockTarget="{Binding ElementName=pressurePane}"/>
                <dxc:Legend x:Name="humidityLegend" 
                            DockTarget="{Binding ElementName=humidityPane}"/>
            </dxc:ChartControl.Legends>
            <dxc:ChartControl.Diagram>
                <dxc:XYDiagram2D>
                    <dxc:XYDiagram2D.AxisX>
                        <dxc:AxisX2D>
                            <dxc:AxisX2D.DateTimeScaleOptions>
                                <dxc:ManualDateTimeScaleOptions MeasureUnit="Hour" 
                                                                MeasureUnitMultiplier="1"/>
                            </dxc:AxisX2D.DateTimeScaleOptions>
                        </dxc:AxisX2D>
                    </dxc:XYDiagram2D.AxisX>
                    <dxc:XYDiagram2D.AxisY>
                        <dxc:AxisY2D x:Name="temperatureAxisY" 
                                     Alignment="Far"/>
                    </dxc:XYDiagram2D.AxisY>
                    <dxc:XYDiagram2D.DefaultPane>
                        <dxc:Pane x:Name="temperaturePane"/>
                    </dxc:XYDiagram2D.DefaultPane>
                    <dxc:XYDiagram2D.Panes>
                        <dxc:Pane x:Name="pressurePane"/>
                        <dxc:Pane x:Name="humidityPane"/>
                    </dxc:XYDiagram2D.Panes>
                    <dxc:XYDiagram2D.SecondaryAxesY>
                        <dxc:SecondaryAxisY2D x:Name="pressureAxisY"/>
                        <dxc:SecondaryAxisY2D x:Name="humidityAxisY"/>
                    </dxc:XYDiagram2D.SecondaryAxesY>
                    <dxc:XYDiagram2D.Series>
                        <dxc:LineSeries2D DisplayName="Temperature"
                                          ArgumentDataMember="DateTime" ValueDataMember="Temperature"
                                          AxisY="{Binding ElementName=temperatureAxisY}"
                                          Legend="{Binding ElementName=temperatureLegend}"
                                          Pane="{Binding ElementName=temperaturePane}"/>
                        <dxc:AreaSeries2D DisplayName="Pressure"
                                          ArgumentDataMember="DateTime" ValueDataMember="Pressure"
                                          AxisY="{Binding ElementName=pressureAxisY}"
                                          Legend="{Binding ElementName=pressureLegend}"
                                          Pane="{Binding ElementName=pressurePane}"/>
                        <dxc:BarSideBySideSeries2D DisplayName="Humidity"
                                                   BarWidth="2"
                                                   ArgumentDataMember="DateTime" ValueDataMember="Temperature"
                                                   AxisY="{Binding ElementName=humidityAxisY}"
                                                   Legend="{Binding ElementName=humidityLegend}"
                                                   Pane="{Binding ElementName=humidityPane}"/>
                    </dxc:XYDiagram2D.Series>
                </dxc:XYDiagram2D>
            </dxc:ChartControl.Diagram>
        </dxc:ChartControl>
    </Grid>
</Window>

The following properties allow you to configure chart elements to series binding:

Symbol Description
Series.Legend Specifies a legend (or its View Model) that contains the series’ legend item.
XYSeries2D.AxisX Specifies the X-axis (or its View Model) that measures the series.
XYSeries2D.AxisY Specifies the Y-axis (or its View Model) that measures a series.
XYSeries2D.Pane Specifies the pane (or its View Model) on which the series is plotted.
ChartControlBase.Legends Returns the collection of chart legends.
XYDiagram2D.AxisX Gets the X-axis.
XYDiagram2D.AxisY Gets the Y-axis.
XYDiagram2D.DefaultPane Provides access to a default pane object.
XYDiagram2D.SecondaryAxesX Gets the collection of secondary X-axes.
XYDiagram2D.SecondaryAxesY Gets the collection of secondary Y-axes.
XYDiagram2D.Panes Provides access to the diagram‘s pane collection.

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the Legend property.

Note

The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

See Also