Data Filtering

  • 4 minutes to read

This document describes how to filter chart data at the chart control level (as opposed to the filtering at the data source level).

NOTE

When dealing with large data sources, filtering data at the chart control level may not be as efficient as filtering at the data source level. If End-Users should not change filtering and sorting parameters, we recommend filtering and sorting your data source at the data level before it is visualized.

You can use the FilterControl or DevExpress.Xpf.Core.FilteringBehavior filter criteria builders to filter chart data or a chart's series data. Refer to the Criteria Language Syntax guide to learn more about filter criteria.

In this guide, the Filtering Behavior is used to demonstrate how to filter chart's data.

Below is an example of a Window containing a Chart Control and a Data Layout Control as the Filtering Behavior's client. To filter a template-generated series, use the following XAML code:

Use the Series.FilterCriteria property to filter series or chart data source using the Criteria Language.

    Public Sub New()
        InitializeComponent()

        Dim dataStreamInfo As StreamResourceInfo = Application.GetResourceStream(New Uri("Data/GDPStatistic.xml", UriKind.RelativeOrAbsolute))
        Dim valueProvider As New XmlGdpValueProvider(dataStreamInfo.Stream)
        DataContext = New MainViewModel(valueProvider)
    End Sub
Public Class MainViewModel
    Private privateGdpValues As IEnumerable(Of GdpValue)
    Public Property GdpValues() As IEnumerable(Of GdpValue)
        Get
            Return privateGdpValues
        End Get
        Private Set(ByVal value As IEnumerable(Of GdpValue))
            privateGdpValues = value
        End Set
    End Property

    'Filter parameters
    Private privateMinGdpValue As Double
    Public Property MinGdpValue() As Double
        Get
            Return privateMinGdpValue
        End Get
        Private Set(ByVal value As Double)
            privateMinGdpValue = value
        End Set
    End Property
    Private privateMaxGdpValue As Double
    Public Property MaxGdpValue() As Double
        Get
            Return privateMaxGdpValue
        End Get
        Private Set(ByVal value As Double)
            privateMaxGdpValue = value
        End Set
    End Property
    Private privateStartYear As Integer
    Public Property StartYear() As Integer
        Get
            Return privateStartYear
        End Get
        Private Set(ByVal value As Integer)
            privateStartYear = value
        End Set
    End Property
    Private privateEndYear As Integer
    Public Property EndYear() As Integer
        Get
            Return privateEndYear
        End Get
        Private Set(ByVal value As Integer)
            privateEndYear = value
        End Set
    End Property
    Private privateCountryNames As IEnumerable(Of String)
    Public Property CountryNames() As IEnumerable(Of String)
        Get
            Return privateCountryNames
        End Get
        Private Set(ByVal value As IEnumerable(Of String))
            privateCountryNames = value
        End Set
    End Property
    Private privateContinentNames As IEnumerable(Of String)
    Public Property ContinentNames() As IEnumerable(Of String)
        Get
            Return privateContinentNames
        End Get
        Private Set(ByVal value As IEnumerable(Of String))
            privateContinentNames = value
        End Set
    End Property


    Public Sub New(ByVal valueProvider As XmlGdpValueProvider)
        GdpValues = valueProvider.GetValues()
        MinGdpValue = GdpValues.Min(Function(gdp) gdp.Value)
        MaxGdpValue = GdpValues.Max(Function(gdp) gdp.Value)
        StartYear = GdpValues.Min(Function(gdp) gdp.Year)
        EndYear = GdpValues.Max(Function(gdp) gdp.Year)
        CountryNames = GdpValues.Select(Function(gdp) gdp.CountryName)
        ContinentNames = GdpValues.Select(Function(gdp) gdp.ContinentName)

    End Sub
End Class
Public Class GdpValue
    <FilterLookup(DataSourceMember := "ContinentNames", UseBlanks := False)> _
    Public Property ContinentName() As String

    <FilterLookup(DataSourceMember := "CountryNames", UseBlanks := False)> _
    Public Property CountryName() As String

    <FilterRange(MaximumMember := "MaxGdpValue", MinimumMember := "MinGdpValue")> _
    Public Property Value() As Double

    <FilterRange(MinimumMember := "StartYear", MaximumMember := "EndYear")> _
    Public Property Year() As Integer
End Class