windowsforms-6171-controls-and-libraries-chart-control-data-representation-filter-series-data.md
This document describes how to filter chart data at the chart control level.
Note
If you use large data sources, we recommend that you filter and sort your data source at the data source level before it is visualized if users should not change filtering and sorting parameters.
The topic contains the following sections:
Bind a series to a data source. See How to: Bind Individual Chart Series to Data for more information on how to bind a series to a data source at design time.
Click the series FilterCriteria property’s ellipsis button in the Properties window (you can also use the Chart Designer or Series Collection Editor to access a series). In the invoked Filter UI Editor, use the plus button to add a new condition. Then, select the column name and criteria operator, and specify the operand value.
The SeriesBase.FilterString property to define an expression used to filter series data. Use Criteria Language Syntax to create the filter expression.
using DevExpress.XtraCharts;
//...
chartControl1.Series[0].FilterString = "Company='DevAV North' And SaleDate=#2018-12-31#";
Imports DevExpress.XtraCharts
'...
chartControl1.Series(0).FilterString = "Company='DevAV North' And SaleDate=#2018-12-31#"
You can use the SeriesBase.FilterCriteria property instead of SeriesBase.FilterString to build and pass a filter expression. Use Criteria Operators to construct the filter expression.
using DevExpress.XtraCharts;
using DevExpress.Data.Filtering;
//...
chartControl1.Series[0].FilterCriteria = new BinaryOperator("Company", "DevAV North", BinaryOperatorType.Equal) &
new BinaryOperator("SaleDate", new DateTime(2018, 12, 31), BinaryOperatorType.Equal);
Imports DevExpress.XtraCharts
Imports DevExpress.Data.Filtering
'...
chartControl1.Series(0).FilterCriteria = New BinaryOperator("Company", "DevAV North", BinaryOperatorType.Equal) And New BinaryOperator("SaleDate", New DateTime(2018, 12, 31), BinaryOperatorType.Equal)
To convert a filter string to its CriteriaOperator equivalent, call the CriteriaOperator.Parse method.
using DevExpress.XtraCharts;
using DevExpress.Data.Filtering;
//...
chartControl1.Series[0].FilterCriteria = CriteriaOperator.Parse("Company='DevAV North' And SaleDate=#2018-12-31#");
Imports DevExpress.XtraCharts
Imports DevExpress.Data.Filtering
'...
chartControl1.Series(0).FilterCriteria = CriteriaOperator.Parse("Company='DevAV North' And SaleDate=#2018-12-31#")
You can access a collection of points the Chart generates based on the filter expression in the ChartControl.BoundDataChanged event handler:
chartControl1.BoundDataChanged += ChartControl1_BoundDataChanged;
//...
private void ChartControl1_BoundDataChanged(object sender, EventArgs e) {
SeriesPointCollection filteredPoints = chartControl1.Series[0].Points;
}
chartControl1.BoundDataChanged += ChartControl1_BoundDataChanged
' ...
Private Sub ChartControl1_BoundDataChanged(ByVal sender As Object, ByVal e As EventArgs)
Dim filteredPoints As SeriesPointCollection = chartControl1.Series(0).Points
End Sub
For example, a form contains a Chart Control, Accordion Control, and Filtering UI Context. To filter a series generated from a template, click the FilteringUIContext’s smart tag and set its Client property to the Chart Control.
Next, call the FilteringUIContext.RetrieveFields() method in the Form.Load event handler to initialize the filters. See the Filtering UI Context: Retrieve Fields and Create the Filter UI section for more information.
private void Form1_Load(object sender, EventArgs e) {
filteringUIContext.RetrieveFields();
}
Private Sub Form1_Load(sender As Object, e As EventArgs)
filteringUIContext.RetrieveFields()
End Sub
Now, the Chart Control uses the auto-generated filter panel to manage series’ SeriesBase.FilterCriteria.
Refer to the Filtering Attributes guide for more information on how to customize the filter panel.
Important
An individual series’s data source cannot be used as the Context’s Client at design time. See the Initialize Filtering UI Context at Runtime section for more information.
To filter an individual series’s data, initialize the Filtering UI Context at runtime. The following code demonstrates how to use a custom filter model to filter series data. Note that in this case, you should use the FilteringUIContext.SetFilterCriteriaBinding method instead of the Client property to bind the Context to the SeriesBase.FilterCriteria property.
Series ProductSeries { get { return chartControl.Series["Products"]; } }
List<Product> Products { get; set; }
FilterViewModel FilterViewModel { get; set; }
private void Form1_Load(object sender, EventArgs e) {
ProductSeries.DataSource = Products;
ProductSeries.ArgumentDataMember = "ProductName";
ProductSeries.ValueDataMembers.AddRange("OnOrderIncome");
filteringUIContext.ParentViewModel = FilterViewModel;
filteringUIContext.ModelType = typeof(Product);
filteringUIContext.SetFilterCriteriaBinding(ProductSeries, s => s.FilterCriteria);
filteringUIContext.RetrieveFields();
}
Private ReadOnly Property ProductSeries() As Series
Get
Return chartControl.Series("Products")
End Get
End Property
Private Property Products() As List(Of Product)
Private Property FilterViewModel() As FilterViewModel
Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load
ProductSeries.DataSource = Products
ProductSeries.ArgumentDataMember = "ProductName"
ProductSeries.ValueDataMembers.AddRange("OnOrderIncome")
filteringUIContext.ParentViewModel = FilterViewModel
filteringUIContext.ModelType = GetType(Product)
filteringUIContext.SetFilterCriteriaBinding(ProductSeries, Function(s) s.FilterCriteria)
filteringUIContext.RetrieveFields()
End Sub
See Also