This is a migrated thread and some comments may be shown as answers.

Change Legend Item From Rectangle to Line with Circle

5 Answers 215 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Angelo
Top achievements
Rank 1
Angelo asked on 21 Nov 2017, 08:11 PM
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?

5 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 24 Nov 2017, 10:29 AM
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.
0
Angelo
Top achievements
Rank 1
answered on 27 Nov 2017, 01:13 PM
I tried the project you created and I get errors when starting the app.
0
Angelo
Top achievements
Rank 1
answered on 27 Nov 2017, 07:26 PM

Hi Martin,

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

Angelo

0
Martin Ivanov
Telerik team
answered on 30 Nov 2017, 09:17 AM
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.
0
Angelo
Top achievements
Rank 1
answered on 01 Dec 2017, 01:06 PM
Thank you very much Martin.  That was very helpful.
Tags
ChartView
Asked by
Angelo
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Angelo
Top achievements
Rank 1
Share this question
or