Articles in this section

How to customize chart legend items in WinForms Chart?

To create a fully custom legend in WinForms Charts, first create and style one or more ChartLegendItem, customizing their text, symbols, and colors. Then, assign an array containing these custom items to the CustomItems property. This action completely replaces the default, auto-generated legend with your custom entries.


ChartLegendItem legendItem1 = new ChartLegendItem();
legendItem1.ItemStyle.ShowSymbol = true;
legendItem1.ItemStyle.Symbol.Shape = ChartSymbolShape.Pentagon;
legendItem1.ItemStyle.Symbol.Size = new Size(15, 15);
legendItem1.ItemStyle.Symbol.Color = Color.RoyalBlue;
legendItem1.Text = "Sales";
legendItem1.IconAlignment = LeftRightAlignment.Left;
legendItem1.ItemStyle.TextColor = Color.RoyalBlue;
legendItem1.ItemStyle.Font = new Font("Verdana", 10f, FontStyle.Italic);
legendItem1.ShowShadow = false;

ChartLegendItem legendItem2 = new ChartLegendItem(); legendItem2.ItemStyle.ShowSymbol = true;
legendItem2.ItemStyle.Symbol.Shape = ChartSymbolShape.Hexagon;
legendItem2.ItemStyle.Symbol.Size = new Size(15, 15);
legendItem2.ItemStyle.Symbol.Color = Color.Red;
legendItem2.Text = "Y Value";
legendItem2.IconAlignment = LeftRightAlignment.Left;
legendItem2.ItemStyle.TextColor = Color.Red;
legendItem2.ItemStyle.Font = new Font("Verdana", 10f, FontStyle.Italic);
legendItem2.ShowShadow = false;

this.chartControl1.Legends[0].CustomItems = new ChartLegendItem[] { legendItem1, legendItem2 };
Dim legendItem1 = New ChartLegendItem()
legendItem1.ItemStyle.ShowSymbol = True
legendItem1.ItemStyle.Symbol.Shape = ChartSymbolShape.Pentagon
legendItem1.ItemStyle.Symbol.Size = New Size(15, 15)
legendItem1.ItemStyle.Symbol.Color = Color.RoyalBlue
legendItem1.Text = "Sales"
legendItem1.IconAlignment = LeftRightAlignment.Left
legendItem1.ItemStyle.TextColor = Color.RoyalBlue
legendItem1.ItemStyle.Font = New Font("Verdana", 10.0F, FontStyle.Italic)
legendItem1.ShowShadow = False

Dim legendItem2 = New ChartLegendItem()
legendItem2.ItemStyle.ShowSymbol = True
legendItem2.ItemStyle.Symbol.Shape = ChartSymbolShape.Hexagon
legendItem2.ItemStyle.Symbol.Size = New Size(15, 15)
legendItem2.ItemStyle.Symbol.Color = Color.Red
legendItem2.Text = "Y Value"
legendItem2.IconAlignment = LeftRightAlignment.Left
legendItem2.ItemStyle.TextColor = Color.Red
legendItem2.ItemStyle.Font = New Font("Verdana", 10.0F, FontStyle.Italic)
legendItem2.ShowShadow = False

lineChart.Legends(0).CustomItems = New ChartLegendItem() {legendItem1, legendItem2}

Output:

chart legend items in chart


Conclusion

I hope you enjoyed learning about how to work with Chart Legend items using Series in WinForms Chart.

You can refer to our WinForms Chart feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our WinForms Chart examples to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forumsDirect-Trac, or feedback portal. We are always happy to assist you! 

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied