Overview
Each series has a collection of data points, and each data point has an X value, and one or more Y values. It is these values that are examined when a search operation occurs, and data points can be located within a series based on a maximum, minimum, or specified value. This topic discusses how to find data points that are present within a series.
Finding data points with specific values is useful when you want to :
- Check a value range.
- Change the visual appearance (color, markers, etc.) of points that have a certain value.
- Set point labels.
- Use a point's position for custom drawing.
Finding Data Points
The Points collection of the Series class exposes several methods for finding points:
- FindValue: Returns the first point in a series with the specified value.
- FindMaxValue: Returns the first point in a series with the largest value.
- FindMinValue: Returns the first point in a series with the smallest value.
The following are a list of points to note:
- If no points match the search criteria a null value will be returned. To test for a null value in VB use a "Not dataPoint Is Nothing" statement.
- Any point value can be examined (e.g. Y2, X, etc.).
- Each of the methods mentioned above can be used in a loop to locate all points that match a search criteria. To find all points from a pre-defined starting index, use a function definition with a startFromIndex parameter.
- If a startFromIndex parameter is provided and a point matching the search criteria is returned, then the startFromIndex parameter will contain the index of the returned data point, otherwise it will be set to -1.
Example
This example demonstrates how to find data points using the first Y value.
Visual Basic | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
Working with Point Finding Methods
By default, all of the point finding methods will examine the first Y value ("Y"). This behavior can be changed by providing the name of the value to look at as a parameter. Possible values are: "X", "Y" (first Y value, the default), "Y2", "Y3", etc.
Example
This example demonstrates how to find data points using non-default values.
Visual Basic | Copy Code |
---|---|
' Find first data point with the maximum X value. Dim maxDataPoint As DataPoint = mySeries.Points().FindMaxValue("X") ' Find the first data point with the minimum second Y value. Dim minDataPoint As DataPoint = mySeries.Points().FindMinValue("Y2") ' Find first data point with an X value of "1/1/2001". Dim dataPoint As DataPoint = mySeries.Points().FindValue(DateTime.Parse("1/1/2001").ToOADate(), "X") |
C# | Copy Code |
---|---|
|
Multiple Points with the Same Value
It is possible that there are multiple points that match the search criteria. However, by default the FindXXX methods will only return the first point in the DataPointCollection that matches the criteria.
To find all points that match a search criteria provide the starting point index of the search using the StartFromIndex parameter. Call the method in a loop and increment the index with each successive method call. When the function returns it will have an index of the next located point, or -1 if nothing was found. Also, if a point does not match the search criteria a value of null will be returned.
Example
This example demonstrates how to find all data points with Y value equal to 10.
Visual Basic | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|
Example
This example demonstrates how to find all data points with a second Y value 10. Once found, we reset the color of these points.
Visual Basic | Copy Code |
---|---|
|
C# | Copy Code |
---|---|
|