Hello everyone,
I was the Simple filtering for a RadChart that telerik has in it's examples and could not get it working from the code behind. I got the filtering working if I hard code the datapoints in the xaml document, but not if I randomly generate them from the code. I know I am missing how to bind the ViewModel and give it the visibility method in the code, I believe that is all I am missing. Any thoughts?
Xaml Code:
Code behind:
I was the Simple filtering for a RadChart that telerik has in it's examples and could not get it working from the code behind. I got the filtering working if I hard code the datapoints in the xaml document, but not if I randomly generate them from the code. I know I am missing how to bind the ViewModel and give it the visibility method in the code, I believe that is all I am missing. Any thoughts?
Xaml Code:
<
Window.Resources
>
<
example:ExampleViewModel
x:Key
=
"ViewModel"
/>
<
Style
x:Key
=
"CustomLegendItemStyle"
TargetType
=
"telerik:ChartLegendItem"
>
<
Setter
Property
=
"Foreground"
Value
=
"Black"
/>
<
Setter
Property
=
"Template"
>
<
Setter.Value
>
<
ControlTemplate
TargetType
=
"telerik:ChartLegendItem"
>
<
Grid
x:Name
=
"PART_MainContainer"
HorizontalAlignment
=
"Stretch"
VerticalAlignment
=
"Top"
Margin
=
"0,0,5,0"
>
<
Path
x:Name
=
"PART_LegendItemMarker"
Height
=
"20"
Width
=
"*"
Style
=
"{TemplateBinding ItemStyle}"
Stretch
=
"Fill"
>
<
Path.Data
>
<
PathGeometry
x:Name
=
"PART_ItemMarkerGeometry"
/>
</
Path.Data
>
</
Path
>
<
CheckBox
IsChecked
=
"True"
VerticalAlignment
=
"Center"
Margin
=
"2,0"
Content
=
"{TemplateBinding Label}"
Foreground
=
"{TemplateBinding Foreground}"
Command
=
"{Binding Path=ChangeSeriesVisibilityCommand, Source={StaticResource ViewModel}}"
CommandParameter
=
"{TemplateBinding Label}"
/>
</
Grid
>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
</
Window.Resources
>
<
Grid
>
<
Grid.RowDefinitions
>
<
RowDefinition
Height
=
"*"
/>
<
RowDefinition
Height
=
"Auto"
/>
</
Grid.RowDefinitions
>
<
telerik:RadChart
x:Name
=
"RadChart1"
>
<
telerik:RadChart.DefaultView
>
<
telerik:ChartDefaultView
ChartLegendPosition
=
"Top"
>
<
telerik:ChartDefaultView.ChartLegend
>
<
telerik:ChartLegend
x:Name
=
"PrimaryLegend"
Header
=
"Click on country to hide/show:"
LegendItemMarkerShape
=
"Square"
LegendItemStyle
=
"{StaticResource CustomLegendItemStyle}"
Foreground
=
"Black"
HeaderFontWeight
=
"Normal"
FontFamily
=
"Segoe UI"
/>
</
telerik:ChartDefaultView.ChartLegend
>
<
telerik:ChartDefaultView.ChartArea
>
<
telerik:ChartArea
Padding
=
"5,10,20,5"
LabelFormatBehavior
=
"None"
LegendName
=
"PrimaryLegend"
/>
</
telerik:ChartDefaultView
>
</
telerik:RadChart.DefaultView
>
</
telerik:RadChart
>
<
TextBlock
Grid.Row
=
"1"
x:Name
=
"sourceText"
TextAlignment
=
"Right"
Text
=
"Source: Eurostat"
FontSize
=
"10"
Foreground
=
"{Binding Source={StaticResource ViewModel}, Path=ApplicationThemeAwareForeground}"
/>
</
Grid
>
</
Window
>
Code behind:
Random rnd =
new
Random();
public
Example()
{
this
.InitializeComponent();
var ds =
new
DataSeries();
for
(var x = 1; x <= 14; ++x)
{
ds.Definition =
new
LineSeriesDefinition();
ds.Definition.ItemLabelFormat =
"0.#"
;
ds.Definition.Visibility = SeriesVisibility.Visible;
ds.LegendLabel = x.ToString();
var dp =
new
DataPoint { YValue =
this
.rnd.Next(10) + 1 };
if
(x == 3 || x == 7)
{
dp.IsEmpty =
true
;
}
ds.Add(dp);
}
this
.RadChart1.DefaultView.ChartArea.DataSeries.Add(ds);
}