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.
Andrew.
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:
<
telerik:RadPieChart
x:Name
=
"StatusChart"
Palette
=
"Metro"
>
<
telerik:RadPieChart.Behaviors
>
<
telerik:ChartSelectionBehavior
DataPointSelectionMode
=
"Single"
/>
</
telerik:RadPieChart.Behaviors
>
<
telerik:PieSeries
Name
=
"statusChartSeries"
ItemsSource
=
"{Binding}"
ShowLabels
=
"True"
>
<
telerik:PieSeries.LegendSettings
>
<
telerik:DataPointLegendSettings
/>
</
telerik:PieSeries.LegendSettings
>
<
telerik:PieSeries.ValueBinding
>
<
telerik:PropertyNameDataPointBinding
PropertyName
=
"Value"
/>
</
telerik:PieSeries.ValueBinding
>
<
telerik:PieSeries.LabelDefinitions
>
<
telerik:ChartSeriesLabelDefinition
>
<
telerik:ChartSeriesLabelDefinition.Binding
>
<
telerik:PropertyNameDataPointBinding
PropertyName
=
"Name"
/>
</
telerik:ChartSeriesLabelDefinition.Binding
>
</
telerik:ChartSeriesLabelDefinition
>
</
telerik:PieSeries.LabelDefinitions
>
</
telerik:PieSeries
>
</
telerik:RadPieChart
>
<
telerik:RadLegend
Name
=
"statusChartLegend"
Items
=
"{Binding ElementName=StatusChart, Path=LegendItems}"
HorizontalAlignment
=
"Left"
VerticalAlignment
=
"Bottom"
/>
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.
Any pointers?
Thanks.
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).
Goran
Then I changed it to
xmlns:telerikLegend="clr-namespace:Telerik.Windows.Controls.ChartView;assembly=Telerik.Windows.Controls.Chart"
now it works.
(http://www.telerik.com/help/wpf/p_telerik_windows_controls_chartview_categoricalstrokedseries_legendsettings.html)
My All dll's version is 2013.2.611.40
Andrew, perhaps you can use the TitleBinding property of the DataPointLegendSettings:
<
telerik:DataPointLegendSettings
TitleBinding
=
"Name"
/>
Regards,
Petar Marchev
Telerik
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.
Regards,
Martin Ivanov
Progress Telerik
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.
Please help.
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:
<
telerik:RadLegend.ItemTemplate
>
<
DataTemplate
>
<
ContentControl
Content
=
"{Binding}"
ContentTemplateSelector
=
"{StaticResource MyCustomTemplateSelector}"
/>
</
DataTemplate
>
</
telerik:RadLegend.ItemTemplate
>
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.
Regards,
Martin Ivanov
Progress Telerik
Hello Martin,
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?
Thanks
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.
Regards,
Martin Ivanov
Progress Telerik
Hello Martin,
How do I print the RadcartesianChart?. I need to print the line series along with x and Y axis(complete graph).
Regrds,
Vinay
You can see how to print the chart in the ChartView's Exporting example in the demos application.
Regards,
Martin Ivanov
Progress Telerik