How to create multiple legends for a chart control in WinForms?
In WinForms Charts, the Essential Chart component supports the use of multiple legends within a single chart control. This feature is particularly useful for enhancing the clarity of legend items when there are a large number of series in the chart. To implement multiple legends, you need to create custom legends and assign the relevant series to each.
You can use custom legends alongside the default legend. If the default legend is not required, set the Visible property to false to hide it.
C#
this.chartControl1.Legend.Visible = false;
this.chartControl1.LegendsPlacement = ChartPlacement.Outside;
ChartLegend legend1 = new ChartLegend(chartControl1);
legend1.Name = "legend 1";
legend1.Alignment = ChartAlignment.Center;
legend1.Position = ChartDock.Top;
legend1.Font = new Font("Segoe UI", 10f, FontStyle.Bold);
ChartLegend legend2 = new ChartLegend(chartControl1);
legend2.Name = "legend 2";
legend2.Alignment = ChartAlignment.Center;
legend2.Position = ChartDock.Bottom;
legend2.Font = new Font("Segoe UI", 10f, FontStyle.Bold);
chartSeries1.LegendName = "legend 1";
chartSeries2.LegendName = "legend 2";
chartControl1.Legends.Add(legend1);
chartControl1.Legends.Add(legend2);
VB
lineChart.Legend.Visible = False
lineChart.LegendsPlacement = ChartPlacement.Outside
Dim legend1 = New ChartLegend(lineChart)
legend1.Name = "legend 1"
legend1.Alignment = ChartAlignment.Center
legend1.Position = ChartDock.Top
legend1.Font = New Font("Segoe UI", 10.0F, FontStyle.Bold)
Dim legend2 = New ChartLegend(lineChart)
legend2.Name = "legend 2"
legend2.Alignment = ChartAlignment.Center
legend2.Position = ChartDock.Bottom
legend2.Font = New Font("Segoe UI", 10.0F, FontStyle.Bold)
ChartSeries1.LegendName = "legend 1"
ChartSeries2.LegendName = "legend 2"
lineChart.Legends.Add(legend1)
lineChart.Legends.Add(legend2)
Output:
Conclusion
I hope you enjoyed learning about how to create multiple legends for a chart control 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 forums, Direct-Trac, or feedback portal. We are always happy to assist you!