차트 컨트롤로 데이터 요소 검색
계열에서 값의 범위 또는 특정 값에 대한 데이터 요소의 X 및 Y 값을 검색할 수 있습니다.특정 값을 사용하여 데이터 요소를 검색하면 다음과 같은 경우에 유용합니다.
값 범위를 확인하려는 경우
특정 값을 가진 요소의 모양을 변경하려는 경우
요소 레이블을 설정하려는 경우
사용자 지정 그리기에 대해 요소 위치를 사용하려는 경우
데이터 요소 검색
Series.Points 컬렉션 속성은 요소 검색을 위한 다양한 메서드를 제공합니다.
FindValue
계열에서 지정된 값을 가진 첫 번째 요소를 반환합니다.FindMaxValue
계열에서 가장 큰 값을 가진 첫 번째 요소를 반환합니다.FindMinValue
계열에서 가장 작은 값을 가진 첫 번째 요소를 반환합니다.
참고
이러한 메서드는 검색 조건과 일치하는 요소가 없을 경우 null 값을 반환합니다.
루프에서 각 메서드를 사용하여 검색 조건과 일치하는 모든 요소를 찾습니다.미리 정의된 시작 인덱스부터 모든 요소를 찾으려면 메서드 중 하나를 startFromIndex 매개 변수와 함께 사용합니다.또한 이 매개 변수를 제공하면 메서드에서는 이를 사용하여 반환된 데이터 요소의 인덱스를 나타냅니다.
다음 코드에서는 첫 번째 Y 값을 기준으로 데이터 요소를 검색하는 방법을 보여 줍니다.
' 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)
// 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);
X, Y2 등과 같은 값을 검색하려면 값의 이름을 제공합니다.다음 코드에서는 X 값을 기준으로 데이터 요소를 검색하는 방법을 보여 줍니다.
' 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")
// 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");
여러 요소 검색
검색 조건과 일치하는 모든 데이터 요소를 찾으려면
startFromIndex 매개 변수를 사용하여 검색의 시작점 인덱스를 제공합니다.
루프에서 메서드를 호출하고 메서드를 호출할 때마다 인덱스를 증가시킵니다.
다음 코드에서는 값 10에 대한 두 번째 Y 값을 검색하고 결과 데이터 요소의 색을 다시 설정하는 방법을 보여 줍니다.
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
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);
}
}
참고 항목
참조
System.Windows.Forms.DataVisualization.Charting
System.Web.UI.DataVisualization.Charting