Configure Chart Legend in DevExpress Presentation API
- 2 minutes to read
A legend allows you to identify series by their color. The DevExpress Presentation API allows you to show, hide, and customize a chart legend.
Access a Chart Legend
Charts API creates a legend once you create a chart. Note that the legend is visible only if a chart has at least one series.
Use the Chart.Legend (or ChartEx.Legend) property to access a Legend object (a LegendEx object for ChartEx) for further customization:
using DevExpress.Docs.Office;
using DevExpress.Docs.Presentation;
Legend legend = chart.Legend;
To remove the legend from the chart, set the Chart.Legend property to null (Nothing in VB.NET).
Set Legend Position and Appearance
Use the following properties to configure legend placement and appearance:
- LegendBase.Position
- Specifies the legend position. Available values include
Bottom,Top,Left,Right, andTopRight. - LegendBase.AllowOverlapChart
- Specifies whether the legend can overlap the chart plot area.
- LegendBase.TextProperties
- Specifies legend text formatting.
The following code snippet positions the legend, formats legend text, and customizes the legend frame:
using DevExpress.Docs.Office;
using DevExpress.Docs.Presentation;
using System.Drawing;
legend.Position = LegendPositionType.TopRight;
legend.AllowOverlapChart = true;
legend.TextProperties = new TextProperties {
FontSize = 16,
Bold = true
};
legend.Fill = new SolidFill(Color.AliceBlue);
legend.OutlineStyle = new OutlineStyle {
Fill = new SolidFill(Color.SlateGray),
Width = 2
};
Customize Individual Legend Entries
The Legend.CustomEntries property allows you to access a collection of legend entries you can customize. Note that custom entries are only available in the Chart.
Use the LegendEntry.TextProperties and LegendEntry.Hidden properties to customize text and visibility of individual legend entries.
The following code snippet customizes the first legend entry that corresponds to the first series in the chart: