Skip to main content
A newer version of this page is available. .

Filtering Data

  • 3 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. We recommend filtering and sorting your data source at the data level before it is visualized if End-Users should not change filtering and sorting parameters.

You can use the FilterControl or Filtering UI Context 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 UI Context is used to demonstrate how to filter chart’s data.

The topic contains the following sections:

Design-Time Filtering UI Context Initialization

As an example, the form contains a Chart Control, Accordion Control and Filtering UI Context. To filter a template-generated series, click the FilteringUIContext’s smart tag and set its Client property to the Chart Control.

Chart_FilteringUIContext

Important

An individual series’ data source cannot be specified as the Context’s Client at design time.

Then, you should initialize filters. Call the FilteringUIContext.RetrieveFields() method in the Form.Load event handler.


private void Form1_Load(object sender, EventArgs e) {
    filteringUIContext.RetrieveFields();
}

Now, the Chart Control uses the Filtering UI to manage its series’ SeriesBase.FilterCriteria.

Chart_Filtering_DesignTimeResult

The next step is filtering UI customization. Refer to the Filtering Attributes guide for more information.

Run-Time Filtering UI Context Initialization

The Filtering UI requires runtime initialization if it should filter an individual series. The following code demonstrates Chart filtering using a custom filter model. 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();
}
See Also