Chart for .NET / User's Guide / Data Manipulation / Subset Operations / Filtering

Filtering

The data series of Nevron Chart for .NET have built-in support for filtering. In general filtering represents the ability to extract a data series subset based on a user specified criteria.

 Performing a Filter operation

The filtering functionality of the data series is exposed by the Filter method of the NDataSeries class. The filter operations can be performed only on data series of type Double. If you attempt to execute the Filter method on a data series of other type the component will raise an exception. The Filter command receives two arguments - the compare method which must be used and the compare value. The method will return an instance of a NDataSeriesSubset object containing the indexes of the values in the data series which match the specified criteria.

The following code retrieves the subset of bar values which are smaller than 50.

C#
Copy Code
NDataSeriesSubset subset = barseries.Values.Filter(CompareMethod.Less, 50);
Visual Basic
Copy Code
Dim subset As NDataSeriesSubset =  barseries.Values.Filter(CompareMethod.Less,50)
 Supported Compare methods

The compare method passed to the Filter function is of type CompareMethod which has the following fields:

More
Less
Equal
MoreOrEqual
LessOrEqual
NotEqual

Internally the filter method iterates through the data series values and performs the compare method against the current value. If the current value satisfies the specified criteria its index is added to the returned subset. The following table describes the operation which is performed by the compare methods:

Compare Method Description
More curValue > compareValue
Less curValue < compareValue
Equal curValue = compareValue
MoreOrEqual curValue >= compareValue
LessOrEqual curValue <= compareValue
NotEqual curValue != compareValue
 Implementing complex filtering

In conjunction with the powerful set operations implemented by the NDataSeriesSubset class the user can implement complex filtering of the data. The following example generates an array of the data series values which are which are bigger than 35 and smaller than 85.

C#
Copy Code
NDataSeriesSubset s1, s2;
s1 = bar.Values.Filter(CompareMethod.More, 35);
s2 = bar.Values.Filter(CompareMethod.Less, 85);
s1.Intersect(s2);

ArrayList arrValues = new ArrayList();
foreach (int index in s1)
{
   arrValues.Add(bar.Values[index]);
}
Visual Basic
Copy Code
Dim s1 As NDataSeriesSubset,s2 As NDataSeriesSubset
s1 = bar.Values.Filter(CompareMethod.More, 35)
s2 = bar.Values.Filter(CompareMethod.Less, 85)
s1.Intersect(s2)

Dim arrValues As ArrayList =  New ArrayList()
Dim index As Integer
For Each index In s1
   arrValues.Add(bar.Values(index))
Next
 Related Examples
Windows forms: All Examples\Data Manipulation\General\Filtering
See Also