Change Legend Item From Rectangle to Line with Circle

6 posts, 0 answers
  1. Angelo
    Angelo avatar
    9 posts
    Member since:
    Nov 2017

    Posted 21 Nov Link to this post

    I have a stacked chart combined with 2 line series.  When i create the legend, it shows all series as rectangles.  How do I make the line series show a colored line with a circle on the legend?
  2. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1475 posts

    Posted 24 Nov Link to this post

    Hello Angelo,

    There are few approaches which I can suggest you in your case.
    • The first one is to define a custom ItemTemplate for RadLegend and define a Path element in it for the geometry. Then you can use an IValueConverter to determine the Geometry of the Path. For example, you can bind the Presenter property of the LegendItem and in the converter check if the property hold a reference to LineSeries, create a line geometry. Otherwise, create a rectangle geometry. Check this approach in the attached project.

    • The second option is to manually populate the RadLegend control with LegendItem objects. In this case you can set the MarkerGeometry of the LegendItems to whatever geometry you like. 

    • The third approach is to create a custom ItemTemplate for RadLegend and define a ContentControl in it. Then create a DataTemplateSelector and asssign it to the ContentTemplateSelector property of the ContentControl. In the selector you can use different template for the series.

    I created a project for all three options. Please give it a try and let me know how it goes.

    Regards,
    Martin Ivanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Angelo
    Angelo avatar
    9 posts
    Member since:
    Nov 2017

    Posted 27 Nov in reply to Martin Ivanov Link to this post

    I tried the project you created and I get errors when starting the app.
  4. Angelo
    Angelo avatar
    9 posts
    Member since:
    Nov 2017

    Posted 27 Nov in reply to Martin Ivanov Link to this post

    Hi Martin,

    Thank you for your reply.  Would it be possible for you to provide another version using purely C# code?

    Angelo

  5. Martin Ivanov
    Admin
    Martin Ivanov avatar
    1475 posts

    Posted 30 Nov Link to this post

    Hello Angelo,

    I converted my code from UserControl1 to C# only, except the ItemTemplate of the legend which is stored in the Application Resources dictionary. Check the attached project. I hope this is a good starting point for implementing your requirement in code-behind.

    Regards,
    Martin Ivanov
    Progress Telerik
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  6. Angelo
    Angelo avatar
    9 posts
    Member since:
    Nov 2017

    Posted 01 Dec in reply to Martin Ivanov Link to this post

    Thank you very much Martin.  That was very helpful.
Back to Top