Skip to main content

Series.FilterCriteria Property

Gets or sets the current filter criteria. This is a dependency property.

Namespace: DevExpress.Xpf.Charts

Assembly: DevExpress.Xpf.Charts.v24.1.dll

NuGet Package: DevExpress.Wpf.Charts

Declaration

[Browsable(false)]
public CriteriaOperator FilterCriteria { get; set; }

Property Value

Type Description
CriteriaOperator

The current filter criteria.

Remarks

Use the FilterCriteria property to create a filter expression that consists of different conditions applied to multiple data columns, and apply it to the series data. All existing filters are reset after you change the FilterCriteria to a new value.

Use CriteriaOperator‘s descendants to specify the FilterCriteria property. Refer to Criteria Operators for more information.

<dxc:ChartControl x:Name="chart" Width="640" Height="360">
    <dxc:XYDiagram2D>
        <dxc:BarSideBySideSeries2D x:Name="series"
                                    DisplayName="Sales" 
                                    DataSource="{DXBinding 'new $local:DevAVSales().GetSalesByRegion()'}"
                                    ArgumentDataMember="Region"
                                    ValueDataMember="Sales">
        </dxc:BarSideBySideSeries2D>
    </dxc:XYDiagram2D>
</dxc:ChartControl>

Code-Behind:

Show code
using System.Data;
using System.Windows;
using DevExpress.Data.Filtering;
namespace FilterStringExample {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();            
            series.FilterCriteria = new BinaryOperator("ProductCategory", "Automation", BinaryOperatorType.Equal);
        }
    }
    public class DevAVSales {
        public DataTable GetSalesByRegion() {
            DataTable table = new DataTable();
            table.Columns.AddRange(new DataColumn[] { new DataColumn("ProductCategory", typeof(string)), 
                                                      new DataColumn("Region", typeof(string)), 
                                                      new DataColumn("Sales", typeof(decimal)) });
            table.Rows.Add("Video players", "Asia", 853D);
            table.Rows.Add("Video players", "Australia", 321D);
            table.Rows.Add("Video players", "Europe", 655D);
            table.Rows.Add("Video players", "North America", 1325D);
            table.Rows.Add("Video players", "South America", 653D);
            table.Rows.Add("Automation", "Asia", 172D);
            table.Rows.Add("Automation", "Australia", 255D);
            table.Rows.Add("Automation", "Europe", 981D);
            table.Rows.Add("Automation", "North America", 963D);
            table.Rows.Add("Automation", "South America", 123D);
            table.Rows.Add("Monitors", "Asia", 1011D);
            table.Rows.Add("Monitors", "Australia", 359D);
            table.Rows.Add("Monitors", "Europe", 721D);
            table.Rows.Add("Monitors", "North America", 565D);
            table.Rows.Add("Monitors", "South America", 532D);
            table.Rows.Add("Projectors", "Asia", 998D);
            table.Rows.Add("Projectors", "Australia", 222D);
            table.Rows.Add("Projectors", "Europe", 865D);
            table.Rows.Add("Projectors", "North America", 787D);
            table.Rows.Add("Projectors", "South America", 332D);
            table.Rows.Add("Televisions", "Asia", 1356D);
            table.Rows.Add("Televisions", "Australia", 232D);
            table.Rows.Add("Televisions", "Europe", 1323D);
            table.Rows.Add("Televisions", "North America", 1125D);
            table.Rows.Add("Televisions", "South America", 865D);
            return table;
        }
    }
}

a chart with an applied filter expression

Alternatively, you can use the Series.FilterString property to pass a filter expression. Note that the FilterString and FilterCriteria properties are dependent. If you update one property, it changes the other property. Refer to Criteria Language Syntax for more information on how to create filter expressions.

series.FilterString = "[ProductCategory]='Automation'";

You can also use the CriteriaOperator.Parse method to convert a filter string to its CriteriaOperator equivalent as follows:

series.FilterCriteria = CriteriaOperator.Parse("[ProductCategory] = 'Automation'");

Example

The following example shows how to use FilterBehavior and AccordionControl to create a UI that allows you to filter chart series data. To apply a filter, bind a series’ Series.FilterCriteria to the FilterBehavior.ActualFilterCriteria property value.

A custom filtering UI for a chart

<dx:ThemedWindow xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core" 
<!-- ... -->
                 xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
                 xmlns:dxfui="http://schemas.devexpress.com/winfx/2008/xaml/core/filteringui"
                 xmlns:dxc="http://schemas.devexpress.com/winfx/2008/xaml/charts"
                 xmlns:dxa="http://schemas.devexpress.com/winfx/2008/xaml/accordion"
                 <!-- ... -->
        <dxc:ChartControl Grid.Column="0" DataSource="{Binding GdpValues}" x:Name="chart">
        <!-- ... -->
            <dxc:XYDiagram2D SeriesDataMember="CountryName" >
                <dxc:XYDiagram2D.SeriesTemplate>
                    <dxc:BarSideBySideSeries2D ArgumentDataMember="Year" ValueDataMember="Value"
                                      FilterCriteria="{Binding ElementName=filterBehavior, Path=ActualFilterCriteria}"/>
                </dxc:XYDiagram2D.SeriesTemplate>
                <!-- ... -->
            </dxc:XYDiagram2D>
        </dxc:ChartControl>
        <dxa:AccordionControl Grid.Column="1" x:Name="accordion">
            <dxmvvm:Interaction.Behaviors>
                <dxfui:FilterBehavior x:Name="filterBehavior" ItemsSource="{Binding ElementName=chart, Path=DataSource}" />
            </dxmvvm:Interaction.Behaviors>
            <dxa:AccordionItem Header="Continent" IsExpanded="True">
                <dxfui:CheckedListFilterElement FieldName="ContinentName"
                                                ShowCounts="False"/>
            </dxa:AccordionItem>
            <dxa:AccordionItem Header="Country" IsExpanded="True">
                <dxfui:CheckedListFilterElement FieldName="CountryName" 
                                                Height="200" 
                                                ShowCounts="False"/>
            </dxa:AccordionItem>
            <dxa:AccordionItem Header="Year" IsExpanded="True">
                <dxfui:RangeFilterElement FieldName="Year"/>
            </dxa:AccordionItem>
            <dxa:AccordionItem Header="Value" IsExpanded="True">
                <dxfui:RangeFilterElement FieldName="Value"/>
            </dxa:AccordionItem>
        </dxa:AccordionControl>
    </Grid>
</dx:ThemedWindow>
using DevExpress.Xpf.Core;
// ...
    public class MainViewModel {
        public IEnumerable<GdpValue> GdpValues { get; private set; }

        public MainViewModel(XmlGdpValueProvider valueProvider) {
            GdpValues = valueProvider.GetValues();
        }
    }
    // ...
    public class GdpValue {
        public string ContinentName { get; set; }
        public string CountryName { get; set; }
        public double Value { get; set; }
        public int Year { get; set; }
    }
See Also