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

Filtering with Grouping

1 Answer 43 Views
Chart
This is a migrated thread and some comments may be shown as answers.
Jim
Top achievements
Rank 1
Jim asked on 14 Jul 2011, 09:18 PM
I'm trying to build a bubble chart using a flat data structure and the GroupSettings to set up different groups base on the value of one of the properties. The chart is working fine so far, however I also need to filter the results based on whether the user checks or unchecks that group in the legend. I've seen the SimpleFiltering example, but that one requires separate mappings be added for each category. Since I don't know at design time how many categories  my result set will have, that example isn't much use at this point. I'm trying to avoid having to filter the results in code and am looking for a built-in way to accomplish this through the tool if possible. Here's the meat of my XAML at this point. The CustomLevendItemStyle essentially comes directly from the SimpleFiltering example, so I won't bother including that.
<telerik:RadChart x:Name="RadBubbleChart" ItemsSource="{Binding Items}" Grid.Row="1" >
 
    <telerik:RadChart.DefaultView>
        <chart:ChartDefaultView ChartLegendPosition="Top">
            <chart:ChartDefaultView.ChartLegend>
                <chart:ChartLegend x:Name="TopLegend"  LegendItemStyle="{StaticResource CustomLegendItemStyle}"  />
            </chart:ChartDefaultView.ChartLegend>
            <chart:ChartDefaultView.ChartArea>
                <chart:ChartArea Legend="{Binding ElementName=TopLegend}" SmartLabelsEnabled="True" NoDataString="Loading..." />
            </chart:ChartDefaultView.ChartArea>
        </chart:ChartDefaultView>
    </telerik:RadChart.DefaultView>
    <telerik:RadChart.SeriesMappings>
        <telerik:SeriesMapping >
            <telerik:SeriesMapping.SeriesDefinition>
                <telerik:BubbleSeriesDefinition ShowItemLabels="True" ShowItemToolTips="True"  />
            </telerik:SeriesMapping.SeriesDefinition>
            <chart:SeriesMapping.GroupingSettings>
                <chart:GroupingSettings ShouldCreateSeriesForLastGroup="True">
                    <chart:ChartGroupDescriptor Member="Source" />
                </chart:GroupingSettings>
            </chart:SeriesMapping.GroupingSettings>
            <telerik:SeriesMapping.ItemMappings>
                <telerik:ItemMapping FieldName="Y" DataPointMember="YValue" />
                <telerik:ItemMapping FieldName="BubbleSize" DataPointMember="BubbleSize" />
            </telerik:SeriesMapping.ItemMappings>
        </telerik:SeriesMapping>
    </telerik:RadChart.SeriesMappings>
</telerik:RadChart>

1 Answer, 1 is accepted

Sort by
0
Tsvetie
Telerik team
answered on 20 Jul 2011, 03:44 PM
Hi Jim,
In the Simple Filtering example, we use the Visibility property of the series definition to show/hide a specific data series. However, in your case, as you yourself mention, this approach is not applicable.

There is no easy way to implement the described behavior. For example, you can filter the data, based on the selection of the legend items. However, in case you filter the data, the legend items will be influenced as well. For example, in case you remove all "Type 1" items from the data, the "Type 1" legend item will be removed as well. That is why, you will have to manager the legend items separately from the filtered data - e.g. bind the Items collection of the legend.

As you can see, such approach will be quite complex and that is why, I would recommend that you use the none-MVVM approach and hide the automatically generated series with code. For example:
RadBubbleChart.DefaultView.ChartArea.DataSeries[0].Definition.Visibility = Telerik.Windows.Controls.Charting.SeriesVisibility.Collapsed;

Regards,
Tsvetie
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Chart
Asked by
Jim
Top achievements
Rank 1
Answers by
Tsvetie
Telerik team
Share this question
or