How to: Filter Data

  • 2 minutes to read

This example shows how to filter chart data at runtime. Refer to Filtering Data for more information.

NOTE

For this example to work correctly, a chart should contain at least one series bound to the "Products" data table in the Northwind Traders database (nwind.mdb file shipped with the XtraCharts demo). Please refer to the Lesson 3 - Bind Chart Series to Data tutorial to see how to bind a series to data.

Use the SeriesBase.FilterCriteria property to filter data with the use of criteria operators.

Alternatively, you can pass a filter expression via the SeriesBase.FilterString property that allows you to build expressions in Criteria Language.

The code below filters data based on the following condition: "CategoryID = 1 or CategoryID = 4 or CategoryID = 7"

using DevExpress.Data.Filtering;
using DevExpress.XtraCharts;
//...

// Obtain the first series of the chart.
Series series = chartControl1.Series[0];

// Filter series data.
series.FilterCriteria = new BinaryOperator("CategoryID", 1, BinaryOperatorType.Equal) |
                        new BinaryOperator("CategoryID", 3, BinaryOperatorType.Equal) |
                        new BinaryOperator("CategoryID", 7, BinaryOperatorType.Equal);

// Alternatively, you can use the FilterString property instead of FilterCriteria.
series.FilterString = "CategoryID = 1 or CategoryID = 3 or CategoryID = 7";
See Also