Back to Devexpress

Legend.DockTarget Property

corelibraries-devexpress-dot-xtracharts-dot-legend-7d3244a3.md

latest5.1 KB
Original Source

Legend.DockTarget Property

Specifies the element (chart or pane) to which the legend is docked.

Namespace : DevExpress.XtraCharts

Assembly : DevExpress.XtraCharts.v25.2.dll

NuGet Package : DevExpress.Charts

Declaration

csharp
[XtraChartsLocalizableCategory(XtraChartsCategory.Layout)]
public ChartElement DockTarget { get; set; }
vb
<XtraChartsLocalizableCategory(XtraChartsCategory.Layout)>
Public Property DockTarget As ChartElement

Property Value

TypeDescription
ChartElement

A ChartElement class descendant representing the dock target for the legend.

|

Remarks

Use the DockTarget , LegendBase.AlignmentVertical and LegendBase.AlignmentHorizontal properties to position the legend relative to its dock target.

For more information, refer to Legends Alignment and Layout.

Example

To add an additional legend to a chart, create a new instance of the Legend class and add it to the ChartControl.Legends collection. Configure its Legend.DockTarget, LegendBase.AlignmentVertical and LegendBase.AlignmentHorizontal properties to specify the legend position within the chart.

Note

Note that the legend will not be shown until it is assigned to the SeriesBase.Legend, Indicator.Legend, ConstantLine.Legend or Strip.Legend property.

Note

A complete sample project is available at https://github.com/DevExpress-Examples/winforms-chart-add-an-additional-legend-to-a-chart

csharp
// Create a new instance of Legend.
Legend macdLegend = new Legend();
chart.Legends.Add(macdLegend);
// Specify the legend position.
macdLegend.DockTarget = diagram.Panes.GetPaneByName("macdPane");
macdLegend.AlignmentHorizontal = LegendAlignmentHorizontal.Left;
macdLegend.AlignmentVertical = LegendAlignmentVertical.Top;

// Assign the data displayed in the legend.
macd.Legend = macdLegend;
vb
' Create a new instance of Legend.
Dim macdLegend As New Legend()
chart.Legends.Add(macdLegend)
' Specify the legend position.
macdLegend.DockTarget = diagram.Panes.GetPaneByName("macdPane")
macdLegend.AlignmentHorizontal = LegendAlignmentHorizontal.Left
macdLegend.AlignmentVertical = LegendAlignmentVertical.Top

' Assign the data displayed in the legend.
macd.Legend = macdLegend

The following code snippet (auto-collected from DevExpress Examples) contains a reference to the DockTarget 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.

winforms-chart-add-an-additional-legend-to-a-chart/CS/LegendsSamples/Form1.cs#L37

csharp
// Position it.
macdLegend.DockTarget = diagram.Panes.GetPaneByName("macdPane");
macdLegend.AlignmentHorizontal = LegendAlignmentHorizontal.Left;

winforms-chart-add-an-additional-legend-to-a-chart/VB/LegendsSamples/Form1.vb#L39

vb
' Position it.
macdLegend.DockTarget = diagram.Panes.GetPaneByName("macdPane")
macdLegend.AlignmentHorizontal = LegendAlignmentHorizontal.Left

See Also

Legend Class

Legend Members

DevExpress.XtraCharts Namespace