liveBook · Manning

Filtering

As explained in D3.js in Action, Third Edition

Data filtering is the technique of selecting only records that satisfy a specified categorical or value-based condition.

Filtering selects only records that satisfy a condition. In an interactive visualization, a user chooses a category and the chart updates to show the matching data. section 7.0

A D3 filtering workflow can proceed as follows:

  • Create filter controls such as All, Women, and Men, and track the active choice. section 7.2
  • Bind the filter definitions to button elements, assign an active class, and display each label. section 7.2
  • Use the selected identifier to retain the complete dataset or keep records whose gender matches the selected value. section 7.2.3
  • Recalculate the histogram bins, bind them to the existing rectangles, and update their y and height attributes. section 7.2.3

Gender-filtered salary histogram

Clicking Women or Men changes the histogram to the corresponding respondents; clicking All restores the whole dataset. The chart’s bars then represent newly calculated bins. section 7.2 section 7.2.3

Figure 7.1 Histogram of the salary distribution among data visualization practitioners in the US with buttons to filter the chart by gender
figure

Inspect the three-button interface and compare the resulting histogram states. section 7.2

How D3.js in Action, Third Edition covers it

How deep it goes
Explains controls, conditional selection, bin recalculation, and rectangle updates, while deferring smooth transitions.
Examples
Uses a salary histogram with All, Women, and Men controls to demonstrate categorical filtering.
What it assumes
Assumes an existing D3 histogram, dataset, bin generator, and scales, while demonstrating the filtering interface and update logic.
What you can do after
Apply it via D3 to update a histogram from a selected categorical subset.
How it connects
Connects D3, data binding, event listeners, histograms, scales, and transitions.

Also explained in

Compare how 33 books explain filtering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of D3.js in Action, Third Edition. The section links point to the parts of the book it draws on.