다음을 통해 공유


차트 컨트롤에서 데이터 필터링

데이터 필터링은 필터링 기준에 따라 데이터 요소를 계열에서 제거하거나 빈 요소로 표시합니다.데이터를 사용하여 작업할 때 필터링 작업을 수행하면 원래의 계열 데이터가 수정되거나 출력이 출력 계열에 저장될 수 있습니다.

경고

여러 계열을 필터링할 경우 모든 계열이 정렬되어 있는지 확인하십시오.그렇지 않으면 필터링 메서드에서 예외가 throw됩니다.자세한 내용은 데이터 맞춤을 참조하십시오.

데이터 필터링

DataManipulator 클래스에서 필터링하는 데 사용되는 속성 및 메서드는 다음과 같습니다.

  • FilterSetEmptyPoints 속성
    데이터 요소를 계열에서 제거할지 또는 빈 요소로 표시할지 지정합니다.

  • FilterMatchedPoints 속성
    기준과 일치하는 데이터 요소를 제거할지 여부를 지정합니다.false로 설정하면 필터링 기준과 일치하지 않는 요소가 필터링됩니다.

    이 속성은 Filter 메서드에만 적용됩니다.

  • Filter 메서드
    날짜 또는 시간 범위를 사용하거나, 데이터 요소 값을 숫자 값과 비교하거나, 일부 사용자 정의 기준을 사용하여 계열의 데이터 요소를 필터링합니다.

  • FilterTopN 메서드
    계열에서 가장 높거나 가장 낮은 값을 가진 요소를 제외한 계열 데이터 요소를 필터링합니다.

날짜 또는 시간 범위별 필터링

데이터 요소의 X 값이 날짜인 경우(계열의 Series.XValueType 속성을 DateTime으로 설정한 경우) 날짜 또는 시간 범위를 기준으로 필터링하려면 Filter 메서드를 사용합니다.계열 데이터는 정의된 범위 요소가 필터링되는 범위로 분할됩니다.날짜 범위를 정의하려면 다음 두 매개 변수를 지정합니다.

  • DateRangeType 클래스의 범위 유형

  • 범위 요소가 있는 문자열.이 문자열은"1-10, 20, 25"와 같이 쉼표와 대시를 포함할 수 있습니다.

다음 코드에서는 "MySeries"라는 계열에서 모든 주말 데이터 요소를 필터링한 다음 해당 월의 1일에 해당하는 요소를 제외한 모든 데이터 요소를 제거합니다.

With Chart1.DataManipulator
        ' Remove weekends.
          .Filter(DateRangeType.DayOfWeek, "0,6", "MySeries")
        
        ' Remove all days of month except of the first. Our 
        ' criteria is the first of each month, and we are 
        ' filtering points that DO NOT match the criteria.
          .FilterMatchedPoints = False
          .Filter(DateRangeType.DayOfMonth, "1", "MySeries")
End With
DataManipulator myDataManip = Chart1.DataManipulator;
// Remove weekends.
  myDataManip.Filter(DateRangeType.DayOfWeek, "0,6", "MySeries");

// Remove all days of month except of the first. Our 
// criteria is the first of each month, and we are 
// filtering points that DO NOT match the criteria.
  myDataManip.FilterMatchedPoints = false;
  myDataManip.Filter(DateRangeType.DayOfMonth, "1", "MySeries");

양극단을 제외한 모든 데이터 필터링

가장 크거나 작은 요소 값을 가진 지정된 수의 요소를 제외한 모든 요소를 계열에서 필터링하려면 FilterTopN 메서드를 사용합니다.이 메서드를 사용하려면 다음 기준을 지정합니다.

  • 유지할 총 요소 수

  • 필터링할 Y 값(예:"Y2").기본값은 첫 번째 Y 값("Y")입니다.

  • 최상위 값을 가져올지 여부.False로 설정한 경우 FilterTopN은 가장 작은 값을 유지합니다.기본값은 True입니다.

아래 코드에서는 FilterTopN 메서드를 사용하는 방법을 보여 줍니다.

With Chart1.DataManipulator
        ' Get the top 10 sales persons, and overwrite the
        ' original series data with the new data.
        ' We assume the first Y value of the points stores
        ' the sales values.
        .FilterTopN(10, "MySeries")
        
        ' Get the 5 points with the smallest X values. 
        ' The filtered data is stored in an output series.
        .FilterTopN(5, "MySeries", "ResultSeries", "X", False)
End With
DataManipulator myDataManip = Chart1.DataManipulator;
// Get the top 10 sales persons, and overwrite the
// original series data with the new data.
// We assume the first Y value of the points stores
// the sales values.
myDataManip.FilterTopN(10, "MySeries"); 

// Get the 5 points with the smallest X values. 
// The filtered data is stored in an output series.
myDataManip.FilterTopN(5, "MySeries", "ResultSeries", "X", false); 

값 기준 필터링

값을 비교하여 필터링하려면 Filter 메서드를 사용합니다.다음 매개 변수를 지정합니다.

  • CompareMethod 클래스의 비교 메서드

  • 비교할 상수 값

  • 필터링할 Y 값(예:"Y2").기본값은 첫 번째 Y 값("Y")입니다.

다음 코드에서는 요소를 상수와 비교하여 필터링하는 방법을 보여 줍니다.

With Chart1.DataManipulator
    ' Filtered points are only marked as empty.
    .FilterSetEmptyPoints = True
    ' Filters all points where the first Y value is greater than 100. 
    ' The input series is overwritten with the filtered data.    
    .Filter(CompareMethod.More, 100, "MySeries")
    ' Filters all points where the X value is less than, or equal to, a specific date.    
    ' The resulting data is stored in an output series, preserving the original data.    
    .Filter(CompareMethod.LessOrEqual, DateTime.Parse("1/1/2001").ToOADate(), "MySeries", "ResultSeries", "X")
End With
DataManipulator myDataManip = Chart1.DataManipulator;

// Filtered points are only marked as empty.
myDataManip.FilterSetEmptyPoints = true;

// Filters all points where the first Y value is greater than 100. 
// The input series is overwritten with the filtered data.    
myDataManip.Filter(CompareMethod.More, 100, "MySeries");

// Filters all points where the X value is less than, or equal to, a specific date.    
// The resulting data is stored in an output series, preserving the original data.    
myDataManip.Filter(CompareMethod.LessOrEqual, DateTime.Parse("1/1/2001").ToOADate(), "MySeries", "ResultSeries", "X");

사용자 지정 기준에 따라 필터링

사용자 지정 기준을 정의하려면 IDataPointFilter 인터페이스를 사용합니다.이 인터페이스에서는 제거할 데이터 요소를 결정하는 FilterDataPoint 메서드를 제공합니다.다음은 FilterDataPoint 메서드의 매개 변수와 해당 반환 값입니다.

  • 필터링되는 데이터 요소 개체

  • 요소가 속하는 계열

  • Series.Points 컬렉션 개체에 있는 데이터 요소의 인덱스

  • 요소를 필터링해야 할 경우 True를 반환하고, 그렇지 않으면 False를 반환합니다.

다음 코드에서는 사용자 정의 기준을 사용하여 요소를 필터링하는 방법을 보여 줍니다.

' Filters points using custom criteria.
Dim filter As New MyPointFilter()
Chart1.DataManipulator.Filter(filter, "MySeries")

' User defined filtering criteria. Filters all points with 
' Y values greater than 100 or less than 10.
Public Class MyPointFilter  Implements IDataPointFilter
    Private Function FilterDataPoints(ByVal point As DataPoint, ByVal series As Series, ByVal pointIndex As Int32) _
      As Boolean Implements IDataPointFilter.FilterDataPoint
      
      If point.YValues(0) > 100.0 Or point.YValues(0) < 10.0 Then
            FilterDataPoints = True
        Else
            FilterDataPoints = False   
        End If          
    End Function
End Class
MyPointFilter filter = new MyPointFilter();
Chart1.DataManipulator.Filter(filter, "MySeries");

// User defined filtering criteria. Filters all points with 
// Y values greater than 100 or less than 10.
public class MyPointFilter : IDataPointFilter 
{    
    private bool FilterDataPoints(DataPoint point, Series series, Int32 pointIndex)
    {
        if((point.YValues(0)>100) || (point.YValues(0)<10))
        {
            FilterDataPoints = true;
        }
        else 
        {
            FilterDataPoints = false;
        }
    }
}

여러 계열 필터링

쉼표로 구분된 입력 계열 문자열의 계열 이름 목록을 지정하여 여러 계열을 필터링합니다.각 계열의 모든 요소는 목록의 첫 번째 계열을 기준으로 필터링됩니다.즉, 첫 번째 계열에서 특정 인덱스를 가진 데이터 요소가 제거되면 동일한 인덱스를 가진 데이터 요소가 모든 계열에서 제거됩니다.

참고 항목

참조

System.Windows.Forms.DataVisualization.Charting

System.Web.UI.DataVisualization.Charting

기타 리소스

데이터 바인딩 및 조작