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.
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.
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; // 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";