D3 Crossfilter Examples

Here is my learning process for getting to grips with crossfilter.

The data is a subset of data on the effects of flouridation. DMFT is a count of Decayed, Missing or Filled Teeth.

Dimension - Simple



Dimension effectively sorting by column. Top giving highest first by default

Country Dimension - display all

var cf.country = cf.dimension(function(d) { return d.Country; });
output cf.country.top(Infinity)

Year Dimension - display highest 4

var cf.year = cf.dimension(function(d) { return d.Year; });
output cf.year.top(4)

DMFT Dimension - display highest 4

var cf.dmft = cf.dimension(function(d) { return d.DMFT; });
output cf.dmft.top(4)


Add a filter to the dimension - just Ireland

var f1 = cf.country.filterExact("Ireland");
output f1.top(Infinity)

Filters are cumulative, adding a filter for year for 1990-2000 gives all Ireland records for the year range. Note filterExact seems to act like filterRange if a list is passed.

var f2 = cf.year.filterExact([1990,2000]);
output f2.top(Infinity)

To get all records for year for 1990-2000, clear the filter for country

var f3 = cf.year.filterRange([1990,2000]);
output f3.top(Infinity)

Range selects greater than or equal to min and less than max, range reduced to 1993-1997

var f3 = cf.year.filterRange([1993,1997]);
output f3.top(Infinity)

Simple dimension and group gives count of items in each group.

var d1 = cf.dimension(function(d) { return d.Country; });
var f1 = d1.group();
output f1.top(Infinity)