Legend of Chart for WinForms C# Tutorial
The Windows Forms Chart control offers the support for the legends that is the descriptions of the charts on the plot. The items in the legend are series specific for the pie chart, and the data points will be displayed in the legend. There will be only one item displayed for line series for each series.
How to Display Legend in Chart
The property of DisplayLegend included in the Chart controls for Windows Forms determines if the legend will be displayed or not. The default value of the DisplayLegend is left as false. The legend for Chart is able to display a legend title and users can display the title text by using the property of LegendTitle.
How to Customize Legend in Chart
Users can change the position of the Chart title by using the property of TitleLocation. If we want to customize more of the title, we can use the TitleElement
Users can also dock the legend to each side of the Chart control by customizing the LegendLocation property.
The property of LegendLocation can be set to float over the chart view. The below C# code shows how to set the legend to stay at the location 120, 10 over the chart area. The LegendOffset property is only taken into consideration when the LegendLocation is set to Float.
How to Setup LegendItem in Chart
The individual data points are the elements that provide legend items in the Pie chart. Besides the Pie chart, the legend items will be provided by the series. Developers need to set two properties, DisplayInLegend and LegendTitle, to each provider so that to control the representation of legend items in the legend. These two properties are.
How to Change Title of LegendItem for Chart
The Items property of the chart legend can be used to customize the title. When users change the text in the legend item, the text in the data point or series will also change. The below C# code can be used to add the line series to the chart and change the title of the legend item via the legend Items collection.
How to Add and Remove LegendItems
To add or remove items from the legend by using the Items collection, we need to create a new instance of LegendItem and add to the Items collection. The Element property of the LegendItem allows users customizing the style of the marker.
UI Controlsfor Windows Forms.NET WinForms UI Overview.NET WinForms UI Features.NET WinForms UI GuideC# WinForms UI DesignVB.NET WinForms UI Design
WinForms UI Controls