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

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

3 Answers 310 Views
ChartView
This is a migrated thread and some comments may be shown as answers.
Matt
Top achievements
Rank 1
Matt asked on 04 Nov 2015, 10:24 PM

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>

3 Answers, 1 is accepted

Sort by
0
Martin Ivanov
Telerik team
answered on 05 Nov 2015, 02:01 PM
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
0
Matt
Top achievements
Rank 1
answered on 05 Nov 2015, 03:15 PM

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.

0
Martin Ivanov
Telerik team
answered on 10 Nov 2015, 09:22 AM
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
Tags
ChartView
Asked by
Matt
Top achievements
Rank 1
Answers by
Martin Ivanov
Telerik team
Matt
Top achievements
Rank 1
Share this question
or