下面的示例演示了在运行时刻如何创建 DataFilter 对象,并且把筛选条件应用于一个系列。 更多信息,请参阅 筛选数据。
为了使此示例能正确工作,图表应该至少包含一个系列,并且此系列被绑定到 Northwind Traders 数据库 (与 XtraCharts 演示一起提供的 nwind.mdb 文件) 中的 "Categories" 数据表。 请参阅下列指南查看如何把系列绑定到图表: 如何: 把各个图表系列绑定到数据 (运行时刻示例)。
下面的代码创建并把下列筛选应用于系列数据: "CategoryID = 1 or CategoryID = 4 or CategoryID = 7"
C# | 复制代码 |
---|---|
using DevExpress.XtraCharts; // ... // Create new data filters and specify conditions for them. DataFilter dataFilter1 = new DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 1); DataFilter dataFilter2 = new DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 4); DataFilter dataFilter3 = new DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 7); // Obtain the first series of the chart. Series series1 = chartControl1.Series[0]; // Set the logical operator used to combine individual data filter conditions for this series. series1.DataFiltersConjunctionMode = ConjunctionTypes.Or; // Remove all other filters. series1.DataFilters.Clear(); // Add new filters to apply to the series data. series1.DataFilters.AddRange(new DataFilter[] {dataFilter1, dataFilter2, dataFilter3}); |
Visual Basic | 复制代码 |
---|---|
Imports DevExpress.XtraCharts ' ... ' Create new data filters and specify conditions for them. Dim dataFilter1 As New DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 1) Dim dataFilter2 As New DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 4) Dim dataFilter3 As New DataFilter("CategoryID", "System.Int32", DataFilterCondition.Equal, 7) ' Obtain the first series of the chart. Dim series1 As Series = chartControl1.Series(0) ' Set the logical operator used to combine individual data filter conditions for this series. series1.DataFiltersConjunctionMode = ConjunctionTypes.Or ' Remove all other filters. series1.DataFilters.Clear() ' Add new filters to apply to the series data. series1.DataFilters.AddRange(New DataFilter() {dataFilter1, dataFilter2, dataFilter3}) |