Framework:Javascript GridAngular GridReact GridVue Grid

Angular Grid: Cross Filtering

Cross-filtering charts allow users to interact with data in an easy and intuitive way. Clicking on chart elements automatically filters values in both the grid and other cross-filter charts.

Cross Filtering

This built-in feature of integrated charts is particularly useful for creating interactive reports and dashboards.

Creating cross-filter charts

Cross-Filter charts are created programmatically using createCrossFilterChart() on the grid's API.

The following snippet shows how a cross-filtering pie chart can be created:

this.gridApi.createCrossFilterChart({
    chartType: 'pie',
    cellRange: {
        columns: ['salesRep', 'sale'],
    },
    aggFunc: 'sum',
});

Note in the snippet above that the sale values are aggregated by the salesRep category as aggFunc: 'sum' is specified.

A corresponding column configuration for the chart above is shown in the following snippet:

<ag-grid-angular
    [columnDefs]="columnDefs"
    /* other grid options ... */>
</ag-grid-angular>

this.columnDefs = [
    { field: 'salesRep', filter: 'agSetColumnFilter', chartDataType: 'category' },
    { field: 'sale', chartDataType: 'series' },
];

Cross-filtering requires that grid filtering is enabled with either a Set Filter or Multi Filter configured on the category column used in the chart. It is also important to define the Chart Data Type as it's not possible to infer the type when all data is filtered out..

The following example shows how to create a simple cross-filtering pie chart. Note the following:

  • Click on a sector of the pie chart to filter rows in the grid by the selected sales rep.
  • Ctrl (Cmd) Click on another sector to additionally adds rows corresponding to the selected sales rep.
  • Click Chart Background to remove / reset the filtering in the grid to restore all rows in the grid.

Cross-filter API

The cross-filter api shares a similar api to Range Chart, however there are different defaults which make sense for cross-filtering.

function createCrossFilterChart(params: CreateCrossFilterChartParams): ChartRef | undefined;
chartType
The type of cross-filtering chart to create.
Options: 'column', 'bar', 'line', 'scatter', 'bubble', 'pie', 'doughnut', 'area'
cellRange
Defines the list of columns to be charted. Note that cross-filter charts include all rows in the grid so there is no need to specify the range of rows.
See cellRange for more details.
chartThemeName
string
The default theme to use for the created chart. In addition to the default options you listed, you can also provide your own custom chart themes.
Options: 'ag-default', 'ag-default-dark', 'ag-material', 'ag-material-dark', 'ag-pastel', 'ag-pastel-dark', 'ag-vivid', 'ag-vivid-dark', 'ag-solar', 'ag-solar-dark'
chartContainer
If the chart is to be displayed outside of the grid then a chart container should be provided. If the chart is to be displayed using the grid's popup window mechanism then leave as undefined.
suppressChartRanges
boolean
By default, when a cross-filter chart is displayed using the grid, the grid will not highlight the range the chart is charting when the chart gets focus. To show the chart range set suppressChartRanges=false.
Default: true
aggFunc
Function
The aggregation function that should be applied to all series data. The built-in aggregation functions are 'sum', 'min', 'max', 'count', 'avg', 'first', 'last'. Alternatively, custom aggregation functions can be provided if they conform to the IAggFunc interface shown here.
aggFunc = (params: AggFuncParams) => any;

interface AggFuncParams {
  values: any[];
  column: Column;
  colDef: ColDef;
  rowNode: RowNode;
  data: any;
  api: GridApi;
  columnApi: ColumnApi;
  context: any;
}
unlinkChart
boolean
When enabled the chart will be unlinked from the grid after creation, any updates to the data will not be reflected in the chart. See Unlinking Charts.
Default: false
chartThemeOverrides
AgChartThemeOverrides
Allows specific chart options in the current theme to be overridden. See Overriding Existing Themes.

cellRange

params > cellRange

Defines the list of columns to be charted. Note that cross-filter charts include all rows in the grid so there is no need to specify the range of rows.

params: {
  ...
  cellRange: {
    columnStart?: string | Column;
    columnEnd?: string | Column;
    columns?: (string | Column)[];
  }
}
columnStart
string | Column
The first column of the range.
columnEnd
string | Column
The last column of the range.
columns
(string | Column)[]
The columns in the range. Used instead of columnStart and columnEnd, particularly when you want non-sequential columns.

Cross-filter Chart Types

The following examples show the different chart types that support cross-filtering:

Example: Sales Dashboard #1

Example: Sales Dashboard #2

Example: Most Populous Cities

Next Up

Continue to the next section to learn about: Time Series.