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

CustomLegendItem Class

An individual custom legend item.

Namespace: DevExpress.XtraCharts

Assembly: DevExpress.XtraCharts.v20.1.dll

NuGet Packages: DevExpress.Charts, DevExpress.WindowsDesktop.Charts

Declaration

public class CustomLegendItem :
    ChartElementNamed,
    ILegendItemData,
    ILegendItem,
    IDisposable

The following members return CustomLegendItem objects:

Remarks

Use the Text property to specify the custom item’s text. To change the item marker appearance, use MarkerColor or MarkerImage properties. The CustomLegendItem.TextVisible and CustomLegendItem.MarkerVisible properties allow you control the item elements’ visibility.

The Legend.CustomItems property provides access to the CustomLegendItemCollection collection that stores custom items. A particular CustomLegendItem object can be accessed within the collection either using indexer notation or by its name (see the CustomLegendItemCollection.Item property).

Example

This example demonstrates how to add a custom item to the legend.

The following code adds a custom legend item with an image and text.

private void Form1_Load(object sender, EventArgs e) {
    double total = CalculateTotal(chartControl.Series[0]);

    CustomLegendItem customLegendItem = new CustomLegendItem();
    customLegendItem.MarkerImage.Image = new Bitmap("..\\..\\Images\\sum-icon.png");
    customLegendItem.MarkerImageSizeMode = ChartImageSizeMode.Zoom;
    customLegendItem.Text = string.Format("Total: ${0}M", total);            
    chartControl.Legend.CustomItems.Add(customLegendItem);
    chartControl.Legend.ItemVisibilityMode = LegendItemVisibilityMode.AutoGeneratedAndCustom;
    chartControl.Legend.Direction = LegendDirection.TopToBottom;
}
public Double CalculateTotal (Series series) {
    double total = 0;
    foreach(SeriesPoint point in series.Points) {
        total += point.Values[0];
    }
    return total;
}

Inheritance

See Also