chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const brush = d3.brushX()
.extent([[margin.left, margin.top], [width - margin.right, height - margin.bottom]])
.on("start brush end", brushed);
const circle = svg.append("g")
.attr("fill-opacity", 0.2)
.selectAll("circle")
.data(Float64Array.from({length: 800}, Math.random))
.join("circle")
.attr("transform", d => `translate(${x(d)},${y()})`)
.attr("r", 3.5);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(brush)
.call(brush.move, [0.3, 0.5].map(x));
function brushed({selection}) {
if (selection === null) {
circle.attr("stroke", null);
} else {
const sx = selection.map(x.invert);
circle.attr("stroke", d => sx[0] <= d && d <= sx[1] ? "red" : null);
}
d3.select(this).call(brushHandle, selection);
}
return svg.node();
}