I have a project where we have an unknown number of series to display and I'd like to make a legend. From the online documentation, it looks like telerik supports all of this, so I must be doing something wrong : the legend just doesn't show up. Could anyone point me to the problem ? Thank you very much.
Out of curiosity, I would also like to know if there's a way to bind to the series properties once they're displayed - e.g. if I had to design a legend by hand, how would I bind to the colours of the series if I don't know them before-hand (because they're dependent on the chosen palette) ?
I've reproduced this in a smaller project, here's my code :
01.
using
System.Collections.Generic;
02.
using
System.Windows;
03.
04.
namespace
telerikTestSandbox
05.
{
06.
public
class
Serie
07.
{
08.
public
Serie(
string
title)
09.
{
10.
Title = title;
11.
Data =
new
List<Point>() {
new
Point(1, 5),
new
Point(2, 15),
new
Point(3, 10) };
12.
}
13.
14.
public
List<Point> Data {
get
;
set
; }
15.
16.
public
string
Title {
get
;
set
; }
17.
}
18.
}
01.
using
System.Collections.Generic;
02.
using
System.Windows;
03.
04.
namespace
telerikTestSandbox
05.
{
06.
/// <summary>
07.
/// Interaction logic for MainWindow.xaml
08.
/// </summary>
09.
public
partial
class
MainWindow : Window
10.
{
11.
public
MainWindow()
12.
{
13.
DataContext =
this
;
14.
15.
Serie serie2 =
new
Serie(
"Test2"
);
16.
serie2.Data =
new
List<Point>() {
new
Point(1, 25),
new
Point(2, 30),
new
Point(3,20)};
17.
ParticipationData.Add(serie2);
18.
Serie serie3 =
new
Serie(
"Test3"
);
19.
serie3.Data =
new
List<Point>() {
new
Point(1, 15),
new
Point(2, 20),
new
Point(3, 25) };
20.
ParticipationData.Add(serie3);
21.
}
22.
23.
public
List<Serie> ParticipationData
24.
{
25.
get
{
return
(List<Serie>)GetValue(ParticipationDataProperty); }
26.
set
{ SetValue(ParticipationDataProperty, value); }
27.
}
28.
29.
// Using a DependencyProperty as the backing store for ParticipationData. This enables animation, styling, binding, etc...
30.
public
static
readonly
DependencyProperty ParticipationDataProperty =
31.
DependencyProperty.Register(
"ParticipationData"
,
typeof
(List<Serie>),
typeof
(MainWindow),
new
PropertyMetadata(
new
List<Serie>() {
new
Serie(
"Test1"
)}));
32.
}
33.
}
01.
<
Window
x:Class
=
"telerikTestSandbox.MainWindow"
03.
xmlns:x
=
"http://schemas.microsoft.com/winfx/2006/xaml"
04.
Title
=
"MainWindow"
Height
=
"350"
Width
=
"525"
05.
xmlns:telerik
=
"http://schemas.telerik.com/2008/xaml/presentation"
06.
xmlns:sys
=
"clr-namespace:System;assembly=mscorlib"
07.
xmlns:local
=
"clr-namespace:telerikTestSandbox"
08.
>
09.
<
Window.Resources
>
10.
<
Style
x:Key
=
"PerformanceVisualisationStyle"
TargetType
=
"telerik:ScatterLineSeries"
BasedOn
=
"{StaticResource ScatterLineSeriesStyle}"
>
11.
<
Setter
Property
=
"PointSize"
Value
=
"3,3"
/>
12.
<
Setter
Property
=
"RenderMode"
Value
=
"Full"
/>
13.
<
Setter
Property
=
"Grid.IsEnabled"
Value
=
"True"
/>
14.
<
Setter
Property
=
"Grid.Visibility"
Value
=
"Visible"
/>
15.
<
Setter
Property
=
"Grid.ShowGridLines"
Value
=
"True"
/>
16.
<
Setter
Property
=
"LegendSettings"
>
17.
<
Setter.Value
>
18.
<
telerik:SeriesLegendSettings
Title
=
"{Binding Title}"
/>
19.
</
Setter.Value
>
20.
</
Setter
>
21.
</
Style
>
22.
</
Window.Resources
>
23.
24.
<
Grid
>
25.
<
Grid.RowDefinitions
>
26.
<
RowDefinition
/>
27.
<
RowDefinition
/>
28.
</
Grid.RowDefinitions
>
29.
<
telerik:RadCartesianChart
Grid.Row
=
"0"
x:Name
=
"Chart"
Palette
=
"Lilac"
Height
=
"250"
Width
=
"500"
>
30.
<
telerik:RadCartesianChart.HorizontalAxis
>
31.
<
telerik:LinearAxis
Title
=
"Position"
/>
32.
</
telerik:RadCartesianChart.HorizontalAxis
>
33.
<
telerik:RadCartesianChart.VerticalAxis
>
34.
<
telerik:LinearAxis
Title
=
"Value"
/>
35.
</
telerik:RadCartesianChart.VerticalAxis
>
36.
<
telerik:RadCartesianChart.SeriesProvider
>
37.
<
telerik:ChartSeriesProvider
Source
=
"{Binding ParticipationData}"
>
38.
<
telerik:ChartSeriesProvider.SeriesDescriptors
>
39.
<
telerik:ScatterSeriesDescriptor
ItemsSourcePath
=
"Data"
XValuePath
=
"X"
YValuePath
=
"Y"
40.
Style
=
"{StaticResource PerformanceVisualisationStyle}"
>
41.
</
telerik:ScatterSeriesDescriptor
>
42.
</
telerik:ChartSeriesProvider.SeriesDescriptors
>
43.
</
telerik:ChartSeriesProvider
>
44.
</
telerik:RadCartesianChart.SeriesProvider
>
45.
46.
<
telerik:RadCartesianChart.Grid
>
47.
<
telerik:CartesianChartGrid
MajorXLinesRenderMode
=
"All"
MajorLinesVisibility
=
"XY"
/>
48.
</
telerik:RadCartesianChart.Grid
>
49.
</
telerik:RadCartesianChart
>
50.
51.
<
telerik:RadLegend
Grid.Row
=
"1"
Background
=
"White"
52.
BorderBrush
=
"Black"
53.
BorderThickness
=
"1"
54.
Items
=
"{Binding LegendItems, ElementName=Chart}"
55.
HorizontalAlignment
=
"Right"
56.
VerticalAlignment
=
"Top"
/>
57.
</
Grid
>
58.
</
Window
>