Telerik RadcartesanChart Reverse the legend order

5 posts, 0 answers
  1. Kannan
    Kannan  avatar
    2 posts
    Member since:
    May 2014

    Posted 21 Apr 2015 Link to this post

    Hi, I am using WPF telerik RadCartesanchart and a Radlegend control which is bound to the chart's legend Items property. It is working, but I would like to have the chart in the same way but legends to be displayed in reverse order, Could someone help me on this?

    Thank you,

    Kannan M

  2. Martin
    Admin
    Martin avatar
    1101 posts

    Posted 22 Apr 2015 Link to this post

    Hi Kannan,

    To achieve the desired effect you can create a custom panel that orders its items in reverse order and set it as an ItemPanel of the RadLegend control. Here is an example:
    public class MyStackPanel : StackPanel
    {
        protected override Size ArrangeOverride(Size finalSize)
        {
            double bottom = 0;
            foreach (UIElement item in this.Children)
            {
                bottom += item.DesiredSize.Height;
            }
     
            foreach (UIElement child in this.Children)
            {
                child.Arrange(new Rect(0, bottom - child.DesiredSize.Height, finalSize.Width, child.DesiredSize.Height));
                bottom -= child.DesiredSize.Height;
            }
     
            return finalSize;
        }
    }

    <telerik:RadLegend Items="{Binding ElementName=chart, Path=LegendItems}">
        <telerik:RadLegend.ItemsPanel>
            <ItemsPanelTemplate>
                <local:MyStackPanel />
            </ItemsPanelTemplate>
        </telerik:RadLegend.ItemsPanel>
    </telerik:RadLegend>
    Please note that this panel implementation is merely a suggestion which is not well tested. This is why I recommend you to test it properly before use it in your application.

    If you have any further questions, please do not hesitate to contact us again.

    Regards,
    Martin
    Telerik
     

    See What's Next in App Development. Register for TelerikNEXT.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Kannan
    Kannan  avatar
    2 posts
    Member since:
    May 2014

    Posted 22 Apr 2015 in reply to Martin Link to this post

    Thanks a lot, that approach solved my issue
  5. Renier Pretorius
    Renier Pretorius avatar
    46 posts
    Member since:
    Apr 2010

    Posted 02 Oct 2015 Link to this post

    Hi Kannan and others,

     I was looking for the same and came across an alternative method which works easier for me. In the view constructor -

    InitializeComponent();
    chart.LegendItems.CollectionChanged += (s, e) =>
      {
          if (legend.Items == null) legend.Items = new Telerik.Windows.Controls.Legend.LegendItemCollection();
          legend.Items.Clear();
          var lst = chart.LegendItems.Reverse();
          foreach (var l in lst)
          {
              legend.Items.Add(l);
          }
      }

  6. Renier Pretorius
    Renier Pretorius avatar
    46 posts
    Member since:
    Apr 2010

    Posted 02 Oct 2015 in reply to Renier Pretorius Link to this post

    Actually got the idea from this forum
Back to Top
UI for WPF is Visual Studio 2017 Ready