Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Chart > Reverse the Legend order?
RadControls for ASP.NET are no longer supported (see this page for reference). In case you have inquiries about the Telerik ASP.NET AJAX controls, post them in the pertinent ASP.NET AJAX forums.

Answered Reverse the Legend order?

Feed from this thread
  • Chris Weinert avatar

    Posted on Mar 8, 2010 (permalink)

    Can the order of the legend be reversed?
    Using a stacked bar chart, for example - Let's say I have 3 series, they're setup like a stop light (top series is red, middle is yellow, bottom is green).

    The colors on the bar chart are: Red on the bottom, then yellow, then green on top (which is opposite from the legend).
    My legend is labeled, so it is clear to the user what the values are, but aesthetically, I've been asked to see if I can reverse the legend.

    Is this possible?
    Thanks!
    -Chris

  • Answer Ves Ves admin's avatar

    Posted on Mar 11, 2010 (permalink)

    Hi Chris Weinert,

    You can wire BeforeLayout event -- at that moment the legend Items collection is populated, so you can reverse it.

    Best regards,
    Ves
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.

  • Chris Weinert avatar

    Posted on Mar 11, 2010 (permalink)

    Worked perfect, thanks a ton!!
    If anyone else is interested, this is how I did it with VB.net:
    Protected Sub RadChart1_BeforeLayout(ByVal sender As ObjectByVal e As System.EventArgs) Handles RadChart1.BeforeLayout  
            'Loop through the legend items in reverse format  
            For Each RadChartLegendLabelItem As Telerik.Charting.LabelItem In RadChart1.Legend.Items.Reverse()  
                'Remove the top-most item (which then decrements the item count of the legend)  
                RadChart1.Legend.Items.RemoveAt(0)  
                'Insert the new (reversed) legend item at the end of the list  
                RadChart1.Legend.Items.Insert(RadChart1.Legend.Items.Count, RadChartLegendLabelItem)  
            Next 
    End Sub 

  • Hung Ha avatar

    Posted on Dec 20, 2010 (permalink)

    Hi,
    I tried applying the code to reverse the legend order, but I got this error message:

    'Reverse' is not a member of 'Telerik.Charting.ChartLabelsCollection'

    Is there anything I can do to remove this error?

  • Giuseppe Giuseppe admin's avatar

    Posted on Dec 20, 2010 (permalink)

    Hello Hung Ha,

    ChartLabelsCollection does not provide built-in support for reversing the items' order and it has never exposed Reverse() method.

    The method Chris is using is actually the extension method IEnumerable<T>.Reverse() that is available in .Net Framework 4 only. Probably your project uses .Net Framework 3.5 hence you are receiving this error message -- you can either upgrade your project to .Net4, or you can implement the reverse functionality on your own.

    Hope this helps.


    All the best,
    Freddie
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.

  • Hung Ha avatar

    Posted on Dec 20, 2010 (permalink)

    Thank you so much for your response. I am using .NET Framework 4, and it does not work. Do you think I miss something to import in the vb files?

  • Giuseppe Giuseppe admin's avatar

    Posted on Dec 21, 2010 (permalink)

    Hi Hung Ha,

    We are unsure what might be the problem with your project. Find attached a runnable sample application that uses .Net Framework 4 and achieves the desired effect.

    Hope this helps.


    All the best,
    Freddie
    the Telerik team

    Check out Telerik Trainer, the state of the art learning tool for Telerik products.
    Attached files

  • Chris Weinert avatar

    Posted on Dec 21, 2010 (permalink)

    Hi Hung Ha,
    As Telerik support mentioned, the reverse() method I was using was an extension method.
    If you're using VB.net, did you try clicking over to the "All" tab (instead of "Common") when looking for the method?

    That's where I found it (see screenshot).
    Attached files

  • Jeff avatar

    Posted on Apr 7, 2011 (permalink)

    How about in C# ?  

    I am getting the Reverse error.  I am running under .Net 4.0

    protected void radchartWebSales_BeforeLayout(object sender, System.EventArgs e)
            {
                //Loop through the legend items in reverse format 
                foreach (Telerik.Charting.LabelItem RadChartLegendLabelItem in radchartWebSales.Legend.Items.Reverse())
                {
                    //Remove the top-most item (which then decrements the item count of the legend) 
                    radchartWebSales.Legend.Items.RemoveAt(0);
                    //Insert the new (reversed) legend item at the end of the list 
                    radchartWebSales.Legend.Items.Insert(radchartWebSales.Legend.Items.Count, RadChartLegendLabelItem);
                }
            }

  • Tsvetie Tsvetie admin's avatar

    Posted on Apr 11, 2011 (permalink)

    Hello Jeff,
    In case your site targets .NET Framework 4.0, then you should be able to use the Reverse extension method of IEnumerable<T>. In case the problem persists, please open a new support ticket and send us a simple running project that demonstrates the problem.

    In the meantime, please make sure that you have added the "using System.Linq;" statement.

    Best wishes,
    Tsvetie
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top

Skip Navigation LinksHome / Community & Support / Developer Productivity Tools Forums / ASP.NET > Chart > Reverse the Legend order?