Articles in this section
Category / Section

How to customize the items in the ChartLegend?

2 mins read


The chart legend can be displayed by setting ShowLegend property as true. Essential Chart supports various properties to customize legend items. ItemsAlignment property is used to specify the alignment of Items in legend. ShowItemShadow property is used to display shadow in items. TextAlignment property is used to align text in legend.


// Aligns Items in the legend

this.chartControl1.Legend.ItemsAlignment = StringAlignment.Center;

// Displays Shadow

this.chartControl1.Legend.ShowItemsShadow = true;

this.chartControl1.Legend.ItemsShadowColor = Color.Red;

this.chartControl1.Legend.ItemsShadowOffset = new Size(2, 2);

this.chartControl1.Legend.ItemsSize = new Size(20, 20);

// Aligns text in the legend

this.chartControl1.Legend.ItemsTextAligment = VerticalAlignment.Top;


' Aligns Items in the legend

Me.ChartControl1.Legend.ItemsAlignment = StringAlignment.Center

' Displays Shadow

Me.ChartControl1.Legend.ShowItemsShadow = True

Me.ChartControl1.Legend.ItemsShadowColor = Color.Red

Me.ChartControl1.Legend.ItemsShadowOffset = New Size(2, 2)

Me.ChartControl1.Legend.ItemsSize = New Size(20, 20)

' Aligns text in the legend

Me.ChartControl1.Legend.ItemsTextAligment = VerticalAlignment.Top

It is also possible to show the custom legend items in Legend. To display custom legend items we need to create an instance of ChartLegendItem class. To display a custom legend item we need to set the visible property to false for the default legend item.

We can customize the style of the legend item also. ShowSymbol, ShowShadow allows us to display or hide the symbol and shadow respectively. We can edit the symbol by using Symbol.Color, Symbol.Shape etc. Using CustomItems under Legend property we can add the item into Legend.


// Hidding default legend item

series2.LegendItem.Visible = false;

// Creating new custom legend item

ChartLegendItem item1 = new ChartLegendItem();

// Setting its properties

item1.ItemStyle.BorderColor = Color.Fuchsia;

item1.ItemStyle.ShowShadow = false;

item1.ItemStyle.ShowSymbol = true;

item1.ItemStyle.Symbol.Color = Color.LightCyan;

item1.ItemStyle.Symbol.Shape = ChartSymbolShape.Diamond;

item1.Text = "Server2";

item1.ItemStyle.TextColor = Color.Green;

// Adding it into chart legend

this.chartControl1.Legend.CustomItems = new ChartLegendItem[] { item1 };


' Hidding default legend item

series2.LegendItem.Visible = False

' Creating new custom legend item

Dim item1 As ChartLegendItem = New ChartLegendItem()

' Setting its properties

item1.ItemStyle.BorderColor = Color.Fuchsia

item1.ItemStyle.ShowShadow = False

item1.ItemStyle.ShowSymbol = True

item1.ItemStyle.Symbol.Color = Color.LightCyan

item1.ItemStyle.Symbol.Shape = ChartSymbolShape.Diamond

item1.Text = "Server2"

item1.ItemStyle.TextColor = Color.Green

' Adding it into chart legend

Me.ChartControl1.Legend.CustomItems = New ChartLegendItem() {item1}

Did you find this information helpful?
Help us improve this page
Please provide feedback or comments
Comments (0)
Please sign in to leave a comment