The data series of the Xceed Chart for WinForms component expose a set of operations that can help you find the index of a specific data item contained within. The 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 that does not contain double values. Both methods return the index of the min or max value contained in the series. The following is an example of their usage:
VB.NET |
|
Dim minIndex As Integer = bar.Values.FindMinValue() Dim maxIndex As Integer = bar.Values.FindMaxValue()
|
C# |
|
int minIndex = bar.Values.FindMinValue(); int maxIndex = bar.Values.FindMaxValue();
|
Finding a Concrete Value
The user can obtain the index of the first appearance of a specific value with the FindValue and FindString methods of the DataSeries class. If the specified value or string is not found in the data series, the methods will return -1.
VB.NET |
|
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
|
C# |
|
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 ... }
|
The FindValue or FindString methods have two overloads with which you can specify a beginning index from which the search must begin. The following example will find the indexes of all data items with value 12.
VB.NET |
|
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
|
C# |
|
int curIndex = bar.Values.FindValue(43); ArrayList indexArray = new ArrayList();
while (curIndex != -1) { indexArray.Add(curIndex); curIndex = bar.Values.FindValue(43, curIndex + 1); }
|
Related Examples
Windows Forms: Data Manipulation\General\Finding
See Also
DataSeries