Can you use Simple Filtering from the code behind?

2 posts, 1 answers
  1. chris
    chris avatar
    32 posts
    Member since:
    Jul 2011

    Posted 25 Aug 2011 Link to this post

    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:
            <example:ExampleViewModel x:Key="ViewModel" />
            <Style x:Key="CustomLegendItemStyle" TargetType="telerik:ChartLegendItem">
                <Setter Property="Foreground" Value="Black" />
                <Setter Property="Template" >
                        <ControlTemplate TargetType="telerik:ChartLegendItem">
                            <Grid x:Name="PART_MainContainer" HorizontalAlignment="Stretch" VerticalAlignment="Top" Margin="0,0,5,0">
                                <Path x:Name="PART_LegendItemMarker"
                                      Style="{TemplateBinding ItemStyle}"
                                        <PathGeometry x:Name="PART_ItemMarkerGeometry" />
                                <CheckBox IsChecked="True"
                                          Content="{TemplateBinding Label}"
                                          Foreground="{TemplateBinding Foreground}"
                                          Command="{Binding Path=ChangeSeriesVisibilityCommand, Source={StaticResource ViewModel}}"
                                          CommandParameter="{TemplateBinding Label}"
                <RowDefinition Height="*" />
                <RowDefinition Height="Auto" />
                <telerik:RadChart x:Name="RadChart1">
                        <telerik:ChartDefaultView ChartLegendPosition="Top">
                                <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:ChartArea Padding="5,10,20,5" LabelFormatBehavior="None" LegendName="PrimaryLegend" />
            <TextBlock Grid.Row="1" x:Name="sourceText" TextAlignment="Right" Text="Source: Eurostat" FontSize="10" Foreground="{Binding Source={StaticResource ViewModel}, Path=ApplicationThemeAwareForeground}" />

    Code behind:
    Random rnd = new Random();
            public Example()
                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;
  2. Answer
    Ves avatar
    2914 posts

    Posted 30 Aug 2011 Link to this post

    Hi Chris,

    Filtering, as well as other data manipulation features in RadChart, like sorting and sampling, are only available in databound scenarios. You will have to configure the series mappings in the chart, build a collection of objects and assign it to RadChart.ItemsSource property. Then you will be able to take advantage of the built-in filtering.

    Best regards,
    the Telerik team

    Thank you for being the most amazing .NET community! Your unfailing support is what helps us charge forward! We'd appreciate your vote for Telerik in this year's DevProConnections Awards. We are competing in mind-blowing 20 categories and every vote counts! VOTE for Telerik NOW >>

Back to Top