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

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 Legend.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.

Note

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

// Create a new custom item.
CustomLegendItem item = new CustomLegendItem();
chart.Legend.CustomItems.Add(item);
// 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;