SeriesDefinition.Visibility +ChartGroupDescriptor

2 posts, 0 answers
  1. leblanc
    leblanc avatar
    56 posts
    Member since:
    Aug 2010

    Posted 21 Nov 2012 Link to this post

    We have a custom behavior that sets mapping.SeriesDefinition.Visibility  with binding to a checkbox mode=twoway.

    It works on charts that do not use group descriptors.

    Attached is screenshot.

                                        <telerik:LineSeriesDefinition LegendDisplayMode="SeriesLabel" SeriesName="Food" ShowItemLabels="False" ShowItemToolTips="True" ItemLabelFormat="#Y" ItemToolTipFormat="#DATAITEM.Food{C2} Food #DATAITEM.FoodAvg{C2} Avg">
                                                <telerik:SeriesAppearanceSettings Fill="#00e8ff" />
                                                <telerik:InteractivitySettings HoverScope="Series" SelectionScope="Series" />
                                                <telerik:ChartGroupDescriptor Member="StoreName" />
                                        <telerik:ItemMapping FieldName="Food" DataPointMember="YValue"   />
                                        <telerik:ItemMapping FieldName="Period" DataPointMember="XCategory" />

    Notice that Food is unchecked = collapsed on seriesdefinition.visiblity.  However, the generated groupped items remain on the chart.
    How else can i get the generated groupping visibility to be turned off?  My next attempt will be to apply seriesmapping programmatically : (
  2. Petar Kirov
    Petar Kirov avatar
    425 posts

    Posted 26 Nov 2012 Link to this post

    Hello Leblanc,

    The Grouping feature of the RadChart creates multiple data series from one SeriesMapping (based on the ChartGroupDescriptor(s)). That's why the bindings to the series definition properties are not replicated.

    The solution would be to traverse the RadChart1.DefaultView.ChartArea.DataSeries collection and manually set the visibility in CheckBox_Click event handler. For example: 
    private void CheckBox_Click(object sender, RoutedEventArgs e)
        var checkBox = (CheckBox)sender;
        string tag = checkBox.Tag as string;
        foreach (DataSeries series in this.RadChart1.DefaultView.ChartArea.DataSeries)
            if (series.Definition.SeriesName == tag)
                series.Definition.Visibility = checkBox.IsChecked == true
                    ? SeriesVisibility.Visible
                    : SeriesVisibility.Collapsed

    In the example above the we show / hide all series which have the same name as the CheckBox tag. Feel free to modify according to your scenario.
    All the best,
    Petar Kirov
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top