Articles in this section
Category / Section

How to customize ChartLegend Items in a WinForms Chart?

In WinForms Chart controlChartLegend provides descriptive information about chart series. To display the legend, set the ShowLegend property to true. You can customize the legend items at design time or runtime using various properties.


this.chartControl1 = new ChartControl();
. . .

this.chartControl1.ShowLegend = true;

// Aligns Items in the legend
this.chartControl1.Legend.ItemsAlignment = StringAlignment.Center;

// Displays Shadow
this.chartControl1.Legend.ShowItemsShadow = true;
this.chartControl1.Legend.ItemsShadowColor = Color.Gray;
this.chartControl1.Legend.ItemsShadowOffset = new Size(1, 1);
this.chartControl1.Legend.ItemsSize = new Size(20, 20);

// Aligns text in the legend
this.chartControl1.Legend.ItemsTextAligment = VerticalAlignment.Top;

Me.ChartControl1 = New ChartControl()
. . .

Me.ChartControl1.ShowLegend = True

' Aligns Items in the legend
Me.ChartControl1.Legend.ItemsAlignment = StringAlignment.Center

' Displays Shadow
Me.ChartControl1.Legend.ShowItemsShadow = True
Me.ChartControl1.Legend.ItemsShadowColor = Color.Gray
Me.ChartControl1.Legend.ItemsShadowOffset = New Size(1, 1)
Me.ChartControl1.Legend.ItemsSize = New Size(20, 20)

' Aligns text in the legend
Me.ChartControl1.Legend.ItemsTextAligment = VerticalAlignment.Top


For more details, refer to the WinForms Chart documentation.


It is possible to display custom legend items by creating an instance of the ChartLegendItem class. Set the Visible property to false for the default legend item to hide it.

The style of the legend item can also be customized. Use ShowSymbol and ShowShadow to display or hide the symbol and shadow, respectively. Adjust the symbol using properties like Symbol.Color and Symbol.Shape. Add items to the legend using the CustomItems property.


this.chartControl1 = new ChartControl();
. . .

this.chartControl1.ShowLegend = true;

// Hidding default legend item
series1.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 };

Me.ChartControl1 = New ChartControl()
. . .

Me.ChartControl1.ShowLegend = True

' Hidding default legend item
series1.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}


For more details, refer to the WinForms Chart documentation.


Conclusion

I hope you enjoyed learning about how to customize the items in the ChartLegend.

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