Back to Devexpress

How to: Add an Additional Legend to a Chart

windowsforms-115945-controls-and-libraries-chart-control-examples-chart-elements-how-to-add-an-additional-legend-to-a-chart.md

latest1.7 KB
Original Source

How to: Add an Additional Legend to a Chart

  • Nov 13, 2018

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 position the legend to the required place.

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.

View Example

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

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

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