Articles in this section

How to customize the order of the legend in a WinForms Chart?

The order of the chart legend in Syncfusion® can be customized through the FilterItems event of the legend. You can reverse the order of legend items by adding them to the ChartLegendItemsCollection class in reverse order.

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

this.chartControl1.ShowLegend = true;
this.chartControl1.Legend.FilterItems += new LegendFilterItemsEventHandler(Legend_FilterItems);

private void Legend_FilterItems(object sender, ChartLegendFilterItemsEventArgs e)
{
    //This creates an new instance of the ChartLegendItemCollection

    ChartLegendItemsCollection item = new ChartLegendItemsCollection();

    for(int i = e.Items.Count - 1; i >= 0; i--)

     item.Add(e.Items[i]);

    e.Items = item;
}
Me.chartControl1 = New ChartControl()
. . .

Me.ChartControl1.ShowLegend = True
AddHandler chartControl1.Legend.FilterItems, AddressOf Legend_FilterItems

Private Sub Legend_FilterItems(ByVal sender As Object, ByVal e As ChartLegendFilterItemsEventArgs)
    ' Creates a new instance of the ChartLegendItemsCollection
    Dim item As ChartLegendItemsCollection = New ChartLegendItemsCollection()

    Dim i As Integer
    For i = e.Items.Count - 1 To 0 Step -1
        item.Add(e.Items(i))
    Next

    e.Items = item
End Sub

For more details, refer to the WinForms Chart documentation.
Before:

After:

Conclusion

I hope you enjoyed learning about how to customize the order of the legend in 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