This is a migrated thread and some comments may be shown as answers.

Can you use Simple Filtering from the code behind?

1 Answer 45 Views
Chart
This is a migrated thread and some comments may be shown as answers.
chris
Top achievements
Rank 1
chris asked on 25 Aug 2011, 03:19 PM
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);
        }

1 Answer, 1 is accepted

Sort by
0
Accepted
Ves
Telerik team
answered on 30 Aug 2011, 08:38 AM
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 >>

Tags
Chart
Asked by
chris
Top achievements
Rank 1
Answers by
Ves
Telerik team
Share this question
or