Xceed Chart for WinForms v4.4 Documentation
Welcome to Xceed Chart for WinForms v4.4 / User Guide / Data Manipulation / Subset Data Manipulation / Filtering

In This Topic
    Filtering
    In This Topic

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

    Performing a Filter Operation

    The filtering functionality of the data series is exposed by the Filter method of the DataSeries class. 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 another type, the component will raise an exception. The Filter command receives two arguments: the compare method that will be used and the compare value. The method will return an instance of a DataSeriesSubset object containing the indexes of the values in the data series matching the specified criteria. 

    The following code retrieves the subset of bar values that are less than 50.

    VB.NET  
    Dim subset As DataSeriesSubset =   barseries.Values.Filter(CompareMethod.Less,50)
    
    C#  
    DataSeriesSubset subset = barseries.Values.Filter(CompareMethod.Less, 50);
    

    Compare Methods Supported by Filter Function

    The compare method passed to the Filter function is of type CompareMethod, which has the following fields (for details, see CompareMethod Enumeration): 

    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 performed by each compare method: 

    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 DataSeriesSubset class, the user can implement complex filtering of the data. The following example generates an array of the data series values that are greater than 35 and less than 85.

    VB.NET  

    Dim s1 As DataSeriesSubset,s2 As DataSeriesSubset

    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
    C#  
    DataSeriesSubset 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]);
    }

    Related Examples

    Windows Forms: Data Manipulation\General\Filtering

    See Also

    Data Series Subsets | DataSeries | DataSeriesSubset