Dundas Chart for ASP.NET
Filtering Data
See Also Send comments on this topic.
Using Dundas Chart > Enterprise Edition Features > Data Manipulation > Filtering Data



Glossary Item Box

Overview

Enterprise Edition Only Feature.

Data is filtered on a series-by-series basis, and when it is filtered, its data points are either removed from the series' Points collection (which is the default behavior), or marked as being empty. The points that get filtered depends on the filtering criteria specified. When you are working with your data, keep in mind that a filtering operation can modify the original series' data, and also that you can use an output series to store modified series data.

 

Caution
When filtering multiple series, you must make certain that all of those series are aligned, otherwise an exception will be thrown.

 

For more information, see the topic on Aligning Series.

 

Note
The term "constant" is used in this article to refer to an integer value.

 

Filtering Data

Several properties and methods of the DataManipulator class are used for filtering, these include:

 

The Filter, and FilterTopN methods take these parameters:

If you specify a Series object as an output series, and that series has not been created and added to the SeriesCollection, then when the function call is made an exception will be thrown. However, if the series has not been created and added to the series collection, but it has been specified as a string expression, then it will automatically be created at run-time, and have default series properties (e.g. column chart type, etc.) assigned to it. In addition to this, the ChartArea property of this series will get set to "Default". If a chart area with the name "Default" already exists in the ChartAreasCollection, then it will be used to draw the chart. If there is no chart area name "Default", then the first ChartArea object in the collection will be used to display the series.

 

Filtering Using Date or Time Ranges

This criteria can be used when the X values of the data points are dates (set by a Series' XValueType property), and is accomplished using the Filter method. Series data is split into ranges where the defined elements of the range are filtered. To define a date range use two parameters:

Example

This example demonstrates how to filter all weekend data points from a series called "MySeries", then we proceed to remove all data points except for the first of the month.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
  ...
  
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


                    
C# Copy Code
using Dundas.Charting.WebControl;
  ...
  
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");


                    

 

Filtering All Points Except for the Largest or Smallest Points

Filters all points from a series except for a specified number of points with the largest or smallest point values. This filtering criteria is used with FilterTopN method, and the following parameters can be used to define the criteria:

Example

This example demonstrates how to use the FilterTopN method.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
  ...
  
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


                    
C# Copy Code
using Dundas.Charting.WebControl;
  ...   
   
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); 


                    

 

Filtering by Comparing Point Values to a Constant

Filters data points by comparing one of their values with a constant, this is done using the Filter method. The following parameters are used:

Example

This example demonstrates how to filter points by comparing them with a constant.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
  ...
  
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


                    
C# Copy Code
using Dundas.Charting.WebControl;
  ...
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");


                    

 

Filtering With User-Defined Criteria

When the filtering criteria is complex and cannot be defined using the methods described above then a user-defined criteria can be specified using the IDataPointFilter interface. This interface exposes the FilterDataPoint method, which determines the data points to be removed. The following are the parameters of the FilterDataPoint method and its return value:

Example

This example demonstrates how to filter points with a user-defined criteria.

Visual Basic Copy Code
Imports Dundas.Charting.WebControl
  ...
  
' 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


                    
C# Copy Code
using Dundas.Charting.WebControl;
  ...
  
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;
        }
    }
}


                    

 

Filtering Multiple Series

The filtering methods of the DataManipulator class allow you to simultaneously filteri multiple aligned series by specifying a comma-separated list of series names. All points in each series will be filtered using the values from the first series. In other words, data points with the same indexes will be removed from all series depending on whether or not a point in the first series is filtered.

 

Some Points to Note

See Also

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