Visibility of an Individual CategoricalDataPoint in a Series Defined by a CategoricalSeriesDescriptor

4 posts, 0 answers
  1. Matt
    Matt avatar
    2 posts
    Member since:
    May 2012

    Posted 04 Nov 2015 Link to this post

    Is there a way to control the Visibility of the individual categorical data points within a BarSeries (or any series), assuming that the series are defined by a ChartSeriesProvider?

    I'm essentially looking to toggle the visibility of the various values available in the CategoryPath property of the CategoricalSeriesDescriptor below.  The entire XAML for my chart is as follows:

             <telerik:RadCartesianChart x:Name="chart" Grid.Column="1" Palette="Windows8">
                <telerik:RadCartesianChart.HorizontalAxis>
                    <telerik:CategoricalAxis/>
                </telerik:RadCartesianChart.HorizontalAxis>
                <telerik:RadCartesianChart.VerticalAxis>
                    <telerik:LinearAxis LabelFormat="P0"/>
                </telerik:RadCartesianChart.VerticalAxis>
                <telerik:RadCartesianChart.SeriesProvider>
                    <telerik:ChartSeriesProvider Source="{Binding ExposureChartData}">
                        <telerik:ChartSeriesProvider.SeriesDescriptors>
                            <!--Current Weight Series-->
                            <telerik:CategoricalSeriesDescriptor ItemsSourcePath="SeriesData" ValuePath="CategoryValue" CategoryPath="CategoryName">
                                <telerik:CategoricalSeriesDescriptor.Style>
                                    <Style TargetType="telerik:BarSeries">
                                        <Setter Property="CombineMode" Value="Cluster"/>
                                        <Setter Property="ShowLabels" Value="True"/>
                                        <Setter Property="LegendSettings">
                                            <Setter.Value>
                                                <telerik:SeriesLegendSettings Title="{Binding SeriesName}"/>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </telerik:CategoricalSeriesDescriptor.Style>
                            </telerik:CategoricalSeriesDescriptor>
                        </telerik:ChartSeriesProvider.SeriesDescriptors>
                    </telerik:ChartSeriesProvider>
                </telerik:RadCartesianChart.SeriesProvider>
            </telerik:RadCartesianChart>

  2. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 05 Nov 2015 Link to this post

    Hello Matt,

    Yes, you should be able to achieve this relatively easy. You can define a DefaultVisualStyle for the BarSeries and bind the Opacity of the visual element to a property from the data point's view model. For example:
    public class DataPointModel
    {
        // other properties
         
        public double Opacity { get; set; }
    }

    <telerik:CategoricalSeriesDescriptor.Style>
        <Style TargetType="telerik:BarSeries">
            <Setter Property="DefaultVisualStyle">
                <Setter.Value>
                    <Style TargetType="Border">
                        <Setter Property="Opacity" Value="{Binding DataItem.Opacity}" />
                        <Setter Property="Background" Value="Green" />
                    </Style>
                </Setter.Value>
            </Setter>
        </Style>
    </telerik:CategoricalSeriesDescriptor.Style>
    You can set the Opacity property of the models which you doesn't want to see to 0.

    Note that when you set the Palette property of RadCartesianChart the series' DefaultVisualStyle is disregarded. In this case, you can use the series' PointTemplate to define a custom visual and bind its Visibility or Opacity to the view model. However, using this approach will disregard the palette.

    Please try this and let me know if it works for you.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  3. UI for WPF is Visual Studio 2017 Ready
  4. Matt
    Matt avatar
    2 posts
    Member since:
    May 2012

    Posted 05 Nov 2015 in reply to Martin Link to this post

    Thanks Martin.  This is nice, but it simply hides the bars for the category, and the CategoryPath is still displayed on the categorical axis.  I'm really looking for the ability to collapse (or remove) a given category (or categories) from each series.  

    I tried to remove a category from the Bar Series in the code behind, but that is an Invalid Operation (Cannot modify the data points that belong to a databound ChartSeries instance.)

    What I ended up doing is creating a collection of my distinct categories, adding an IsVisible property, and any time the visibility property of one of my distinct categories is changed (which is displayed via a checkbox items control), I rebuild the entire chartseriesprovider's data source​, but I'll remove any IsVisible=false categories BEFORE the data source binding is updated.  This is kind of clunky, but it works.

     On a side note, per your response, when I implemented your code, the palette was not disregarded.  Just thought I'd mention that.

     

    Thanks.

  5. Martin
    Admin
    Martin avatar
    1099 posts

    Posted 10 Nov 2015 Link to this post

    Hello Matt,

    Thank you for the additional information. 

    RadChartView doesn't support the desired effect out of the box. However, you can achieve it by modifying the items source of the chart's series provider. For example, if you want to remove "Category 1" you can remove all data points view models which has set their Category to "Category 1'. If you just want to hide the category you can remove the data points from the source and store them in a collection from which you can restore them later.

    I hope this helps.

    Regards,
    Martin
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top