New to Telerik UI for WinFormsStart a free 30-day trial

How to Reverse the Sequence of Legend Items

Updated over 6 months ago

Environment

Product VersionProductAuthor
2022.1.222RadChartView for WinFormsDinko Krastev

Description

When the Legend of the RadChartView is shown, the items inside will be ordered in the same way as the series inside the chart Series collection. In scenario where we have stack bar series, the series will be ordered from bottom to top, while the legend items will be ordered from top to bottom.

Solution

We can reverse the order of the legend items so that is more readable for the end user.

C#

public RadForm1()
{
    InitializeComponent();
    this.Load += RadForm1_Load;
}

private void RadForm1_Load(object sender, EventArgs e)
{
    var legendItems = new List<LegendItem>(this.radChartView1.ChartElement.LegendElement.Items.Reverse());
    this.radChartView1.ChartElement.LegendElement.Items.Clear();
    foreach (var legendItem in legendItems)
    {
        this.radChartView1.ChartElement.LegendElement.Items.Add(legendItem);
    }
}

In this article
EnvironmentDescriptionSolution
Not finding the help you need?
Contact Support