Dundas Chart for ASP.NET
Finding Data Points
See Also Send comments on this topic.
Working with Data > Finding Data Points

Glossary Item Box

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 :

 

Finding Data Points

The Points collection of the Series class exposes several methods for finding points:

 

The following are a list of points to note:

Example

This example demonstrates how to find data points using the first Y value.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
  ...
' Find the first data point with the maximum Y value.
Dim maxDataPoint As DataPoint = mySeries.Points().FindMaxValue()
' Find the first data point with the minimum Y value.
Dim minDataPoint As DataPoint = mySeries.Points().FindMinValue()
' Find the first data point with a first Y value of 10.
Dim dataPoint As DataPoint = mySeries.Points().FindValue(10.0)


                    
C# Copy Code
using Dundas.Charting.WebControl;
  ...
// Find the first data point with the maximum Y value.  
DataPoint maxDataPoint = mySeries.Points().FindMaxValue();
// Find the first data point with the minimum Y value.
DataPoint minDataPoint = mySeries.Points().FindMinValue();
// Find the first data point with a first Y value of 10.
DataPoint dataPoint = mySeries.Points().FindValue(10);


                    

 

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
// Find first data point with the maximum X value.
DataPoint maxDataPoint = mySeries.Points().FindMaxValue("X");
// Find the first data point with the minimum second Y value.
DataPoint minDataPoint = mySeries.Points().FindMinValue("Y2");
// Find first data point with an X value of "1/1/2001".
DataPoint dataPoint = mySeries.Points().FindValue(DateTime.Parse("1/1/2001").ToOADate(), "X");


                    

 

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
Imports Dundas.Charting.WebControl
  ...
' Find all data points with a value 10.  
Dim dataPoint As DataPoint = 0
Dim pointIndex As Integer
pointIndex = 0

Do While (Not (dataPoint) Is Nothing)
    dataPoint = Chart1.Series("MySeries").Points.FindValue(10, "Y", pointIndex)
    ' Do something with points found.
    If (Not (dataPoint) Is Nothing) Then
      ...
    End If
    pointIndex = (pointIndex + 1)
Loop


                    
C# Copy Code
using Dundas.Charting.WebControl;
  ...
// Find all data points with a value 10.
DataPoint dataPoint = Chart1.Series["MySeries"].Points.FindValue(10, "Y", ref pointIndex);
int pointIndex = 0;

while(dataPoint!=null)
{
    dataPoint = Chart1.Series["MySeries"].Points.FindValue(10, "Y", ref pointIndex);
    pointIndex++;   
    // Do something with points found.
    if(dataPoint != null)
    {
      ...
    }
}


                    

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
Imports Dundas.Charting.WebControl
  ...
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  'Find all points with a second Y value equal to 10, and change their color.
  Dim index As Integer = 0
  'Find first point with a Y2 value of 10.
  Dim dataPoint As DataPoint = Chart1.Series("Series1").Points.FindValue(10, "Y2", index)
  While Not (dataPoint Is Nothing)
        dataPoint.Color = Color.FromArgb(255, 128, 128)
        'Find all other data points with a second Y value 10.
        index += 1
        dataPoint = Chart1.Series("Series1").Points.FindValue(10, "Y2", index)
  End While
End Sub


                    
C# Copy Code
using Dundas.Charting.WebControl;
  ...    
private void Page_Load(object sender, System.EventArgs e)
{
    // Find all points with a second Y value equal to 10, and change their color.
    int index = 0;
    // Find first point with a Y2 value of 10.
    DataPoint dataPoint = Chart1.Series("Series1").Points.FindValue(10, "Y2", index);
    while(!(dataPoint == null)) 
    {
        dataPoint.Color = Color.FromArgb(255, 128, 128);
        // Find all other data points with a second Y value 10.
        index++;
        dataPoint = Chart1.Series("Series1").Points.FindValue(10, "Y2", index);
    }
}


                    

See Also

Copyright © 2001 - 2009 Dundas Data Visualization, Inc. and others.