Back to Devexpress

Series.FilterString Property

wpf-devexpress-dot-xpf-dot-charts-dot-series-133790ee.md

latest8.4 KB
Original Source

Series.FilterString Property

Gets or sets the series’s filter expression. This is a dependency property.

Namespace : DevExpress.Xpf.Charts

Assembly : DevExpress.Xpf.Charts.v25.2.dll

NuGet Package : DevExpress.Wpf.Charts

Declaration

csharp
public string FilterString { get; set; }
vb
Public Property FilterString As String

Property Value

TypeDescription
String

The current filter expression.

|

Remarks

Use the FilterString property to specify 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 FilterString to a new value.

Use Criteria Language Syntax to create a filter expression. Then, assign the expression to the FilterString property:

xaml
<dxc:ChartControl x:Name="chart">
    <dxc:XYDiagram2D>
        <dxc:BarSideBySideSeries2D DisplayName="Sales" 
                                   x:Name="series"
                                   DataSource="{DXBinding 'new $local:DevAVSales().GetSalesByRegion()'}"
                                   ArgumentDataMember="Region"
                                   ValueDataMember="Sales" 
                                   FilterString="[ProductCategory]='Automation'" 
                                   LabelsVisibility="True"/>
        <dxc:XYDiagram2D.AxisX>
            <dxc:AxisX2D TickmarksMinorVisible="False">
                <dxc:AxisX2D.QualitativeScaleOptions>
                    <dxc:QualitativeScaleOptions GridLayoutMode="GridShiftedLabelCentered"/>
                </dxc:AxisX2D.QualitativeScaleOptions>
            </dxc:AxisX2D>
        </dxc:XYDiagram2D.AxisX>
    </dxc:XYDiagram2D>
</dxc:ChartControl>

Code-Behind:

Show code

csharp
using System.Data;
using System.Windows;
namespace FilterStringExample {
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();
        }
    }
    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;
        }
    }
}
vb
Imports System.Data
Imports System.Windows
Namespace FilterStringExample
    Public Partial Class MainWindow
        Inherits Window
        Public Sub New()
            InitializeComponent()
        End Sub
    End Class
    Public Class DevAVSales
        Public Function GetSalesByRegion() As DataTable
            Dim table As DataTable = New DataTable()
            table.Columns.AddRange(New DataColumn() {New DataColumn("ProductCategory", GetType(String)), New DataColumn("Region", GetType(String)), New DataColumn("Sales", GetType(Decimal))})
            table.Rows.Add("Video players", "Asia", 853R)
            table.Rows.Add("Video players", "Australia", 321R)
            table.Rows.Add("Video players", "Europe", 655R)
            table.Rows.Add("Video players", "North America", 1325R)
            table.Rows.Add("Video players", "South America", 653R)
            table.Rows.Add("Automation", "Asia", 172R)
            table.Rows.Add("Automation", "Australia", 255R)
            table.Rows.Add("Automation", "Europe", 981R)
            table.Rows.Add("Automation", "North America", 963R)
            table.Rows.Add("Automation", "South America", 123R)
            table.Rows.Add("Monitors", "Asia", 1011R)
            table.Rows.Add("Monitors", "Australia", 359R)
            table.Rows.Add("Monitors", "Europe", 721R)
            table.Rows.Add("Monitors", "North America", 565R)
            table.Rows.Add("Monitors", "South America", 532R)
            table.Rows.Add("Projectors", "Asia", 998R)
            table.Rows.Add("Projectors", "Australia", 222R)
            table.Rows.Add("Projectors", "Europe", 865R)
            table.Rows.Add("Projectors", "North America", 787R)
            table.Rows.Add("Projectors", "South America", 332R)
            table.Rows.Add("Televisions", "Asia", 1356R)
            table.Rows.Add("Televisions", "Australia", 232R)
            table.Rows.Add("Televisions", "Europe", 1323R)
            table.Rows.Add("Televisions", "North America", 1125R)
            table.Rows.Add("Televisions", "South America", 865R)
            Return table
        End Function
    End Class
End Namespace

You can use the following code to set the FilterString property at runtime:

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

Result:

Alternatively, you can use the FilterCriteria property to set the filter expression. See Criteria Operators for information on supported syntax. Note that the FilterString and FilterCriteria properties are dependent. If you update one property, it changes the other property.

csharp
series.FilterCriteria = new BinaryOperator("ProductCategory", "Automation", BinaryOperatorType.Equal);
vb
series.FilterCriteria = new BinaryOperator("ProductCategory", "Automation", BinaryOperatorType.Equal)

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

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

See Also

Filter Chart Data

Series Class

Series Members

DevExpress.Xpf.Charts Namespace