score:12

Accepted answer

The node desired in the argument for d3.brushSelection is the g element corresponding to your brush.

So you could access the selection either via

d3.brushSelection(d3.select(".brush").node())

or, with a slight change to your code,

var xBrush = d3.brushX()
  .extent([[0,0], [xWidth,xHeight]])
  .on("brush", brushed);

var theBrush = xChart.append("g")
  .attr("class", "brush")
  .call(xBrush);

d3.brushSelection(theBrush.node());

Note that if your brush's selection is empty, the function returns null.


Related Query