How to: Add a Custom Legend Item

To add a new custom item to a legend, create a new instance of the CustomLegendItem class and add it to the LegendBase.CustomItems collection. Then, configure the custom item, for example, using the CustomLegendItem.Text property to set the item’s text and the CustomLegendItem.MarkerImage property to set an item’s image.


To show custom and automatically generated legend items, set the LegendBase.ItemVisibilityMode to AutoGeneratedAndCustom.

View Example

// Create a new custom item.
CustomLegendItem item = new CustomLegendItem();
// Specify its text and marker.
item.Text = "Custom Legend Item";
Bitmap bitmap = new Bitmap("Image\\DXLogo_16x16.png");
item.MarkerImage.Image = bitmap;
// Set a value indicating that both autogenerated and custom items are displayed.
chart.Legend.ItemVisibilityMode = LegendItemVisibilityMode.AutoGeneratedAndCustom;