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:
    <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);
            }
  2. Answer
    Ves
    Admin
    Ves avatar
    2879 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,
    Ves
    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 >>

  3. UI for WPF is Visual Studio 2017 Ready
Back to Top