Nevron .NET Vision
Chart for .NET / User's Guide / Data Manipulation / General Operations / Finding

In This Topic
    Finding
    In This Topic

    The data series expose a set of operations which can help you find the index of a specific data item contained in them. Following is a description of these methods.

     Finding minimum and maximum values

    The FindMinValue and FindMaxValue methods can be used to find the index of the min and max values of a data series. The methods will raise an exception if you try to invoke them on a data series, which does not contain double values. Both methods return the index of the min or max value contained in the series. Following is an example of their usage:

    C#
    Copy Code
    int minIndex = bar.Values.FindMinValue();
    int maxIndex = bar.Values.FindMaxValue();
    
    Visual Basic
    Copy Code
    Dim minIndex As Integer = bar.Values.FindMinValue()
    Dim maxIndex As Integer = bar.Values.FindMaxValue()
    
     Finding a concrete value

    You can obtain the index of the first appearance of a specific value with the help of the FindValue and FindString methods of the NDataSeries class. If the specified value or string is not found in the data series the methods will return -1.

    C#
    Copy Code
    int nFirstIndex = bar.Values.FindValue(43);
    if (nFirstIndex == -1)
    {
       // do something if value 43 not found
       ...
    }
    else
    {
       // do something if value 43 is found
       ...
    }
    
    nFirstIndex = bar.Labels.FindString("LabelToSearchFor");
    if (nFirstIndex == -1)
    {
       // do something if label is not found
       ...
    }
    else
    {
       // do something if label is found
       ...
    }
    
    Visual Basic
    Copy Code
    Dim nFirstIndex As Integer =  bar.Values.FindValue(43)
    If nFirstIndex = -1 Then
       ' do something if value 43 not found
       ...
    Else
       ' do something if value 43 is found
       ...
    End If
    
    nFirstIndex = bar.Labels.FindString("LabelToSearchFor")
    If nFirstIndex = -1 Then
       ' do something if label is not found
       ...
    Else
       ' do something if label is found
       ...
    End If
    

    The FindValue or FindString methods have two overloads, with which you can specify a start index from which the search must begin. The following example will find the indexes of all data items with value 12.

    C#
    Copy Code
    int curIndex = bar.Values.FindValue(43);
    ArrayList indexArray = new ArrayList();
    
    while (curIndex != -1)
    {
       indexArray.Add(curIndex);
       curIndex = bar.Values.FindValue(43, curIndex + 1);
    }
    
    Visual Basic
    Copy Code
    Dim curIndex As Integer =  bar.Values.FindValue(43)
    Dim indexArray As ArrayList =  New ArrayList()
    
    While curIndex <> -1
       indexArray.Add(curIndex)
       curIndex = bar.Values.FindValue(43, curIndex + 1)
    End While
    
     Related Examples
    Windows forms: All Examples\Data Manipulation\General\Finding
    See Also