I am struggling to include a <telerik:RadLegend> tag in my code. I have been using your documentation at http://www.telerik.com/help/wpf/radlegend-overview.html as a reference but always get an error message.
I have included a reference to Telerik.Windows.Controls.dll as well as including xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" as a namespace declaration in my XAML, but whenever I try to use a <telerik:RadLegend> tag I get an error stating "The type 'telerik:RadLegend' was not found. Verify that you are not missing an assembly reference and that all referenced assemblies have been build."
Any help on this would be appreciated.
13 Answers, 1 is accepted
I am also having problems with RadLegend, but of other nature, so I bumped to your post while searching for information. Probably the reason that you receive such error is that you are having an older version of Telerik.Windows.Controls.dll referenced in your project. If I am not mistaken this control has been introduced in v2013_1_0220.
Since RadLegend currently supports only ChartView controls, you will also need to add reference to Telerik.Windows.Controls.Chart.dll and Telerik.Windows.Data.dll.
That was indeed the problem. I'd read in another forum post that the control was introduced Q4 2012, which is when we got the dlls. Updating to the latest dlls sorted the problem and I can now show legends with my pie charts.
However I am now having another problem. I am populating my chart by binding the Item Source and setting the value and label of each section of the pie chart. Now whenever I set up a legend the legend labels only showing the percentages and I can't find a way of setting them to show the chart labels. Is there a way to set up the legend so that it shows the same labels I set on the chart?
Here is an example of what I'm trying to do:
I have tried to set up the binding of the Legend in a similar way to the chart values and labels, using telerik:RadLegend.Items but they don't seem to have a telerik:PropertyNameDataPointBinding value.
RadLegend contains ItemTemplate property, which you can use for this purpose.You can access your custom type Name property using Presenter.DataItem.Name.
What I am having problems with, is that if a number of items is dynamically changed in the PieChart (Example from 5 slices to 4), RadLegend will still show 5 items, while PieChart will show 4).
Then I changed it to
now it works.
My All dll's version is 2013.2.611.40
Andrew, perhaps you can use the TitleBinding property of the DataPointLegendSettings:
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
i have the legend items getting displayed in the chart area. I should be able to select and deselect the legend items based on the user preference. Is there any option to that?
Please post your answers
The RadLegend control doesn't support selection. Instead, you can use RadListBox with a custom ItemTemplate.
Thank you Martin.
I have one more doubt. Can we add more than one <telerik:RadLegend.ItemTemplate> in the radlegend control .
If not how do we acess the LIneseries of the radcartesian chart from the control that is placed outside the radcartesian chart area.
You can set only a single ItemTemplate. However, if you want you can implement template selection using a ContentControl and its ContentTemplateSelector property. For example:
About accessing the series of the chart, you can use the Series property of RadCartesianChart. The property holds a collection with the chart's series. Alternatively, if you define the series in XAML you can set their Name property and then use it in code to access the series.
Additionally, I've found an old project of main that shows how to implement some custom selection-like behavior in RadLegend. I attached it here so you can give it a try and see if this could be a good starting point for implementing your requirement.
I have ellipses on the line series of the radcartesianchart. I have two horizontal annotations namely high and low. If the ellipses of the line series crosses these annotations, The ellipses should change their color. Could you please provide a solution for this?
We don't have an example showing this. However, you can achieve this using the DefaultVisualStyle property of the series . Here are few steps to follow in order to implement this:
- Define a property of type Brush in the view model of the data point.
- When the value from the view model of the data point crosses the low/high line value, set the Brush property to another color.
- Define a Style that targets the WPF native Path control and set it to the DefaultVisualStyle property of the series.
- Define a Setter in the Style that sets the Width and Height properties.
- Define a Setter in the Style that sets the Fill property. Bind the value of the setter to the Brush property define the view model of the data point (see point 1). Also keep in mind that if the Palette property of the chart is set the Setter with the Fill property won't work.
How do I print the RadcartesianChart?. I need to print the line series along with x and Y axis(complete graph).
You can see how to print the chart in the ChartView's Exporting example in the demos application.