E.g. of brush for scatterplot
http://stackoverflow.com/questions/14665482/moving-scatter-plot-circles-with-context-zooming-and-brush-in-d3
by Nivaldo
CSS
svg {
font: 10px sans-serif;
background-color: antiquewhite;
}
path {
fill: steelblue;
}
.axis path,
.axis line {
fill: none;
stroke: #000;
shape-rendering: crispEdges;
}
.brush .extent {
stroke: #fff;
fill-opacity: .125;
shape-rendering: crispEdges;
}
.dot {
fill: orangered;
}
JavaScript
var margin = {top: 80, right: 30, bottom: 100, left: 80},
margin2 = {top: 430, right: 30, bottom: 20, left: 80},
width = 960 - margin.left - margin.right,
height = 500 - margin.top - margin.bottom,
height2 = 500 - margin2.top - margin2.bottom;
var data = [
{
'Wed Jan 23 00:00:00 IST 2013': 3383387
}, {
'Thu Jan 24 00:00:00 IST 2013': 1233000
}, {
'Fri Jan 25 00:00:00 IST 2013': 4383387
}, {
'Sat Jan 26 00:00:00 IST 2013': 2344567
}, {
'Sun Jan 27 00:00:00 IST 2013': 3457631
}, {
'Mon Jan 28 00:00:00 IST 2013': 4000023
}, {
'Tue Jan 29 00:00:00 IST 2013': 2330002
}, {
'Wed Jan 30 00:00:00 IST 2013': 1234756
}];
var format = d3.time.format("%a %b %d %H:%M:%S IST %Y");
var parseDate = d3.time.format("%b %Y").parse;
var x = d3.time.scale().range([0, width]),
x2 = d3.time.scale().range([0, width]),
y = d3.scale.linear().range([height, 10]),
y2 = d3.scale.linear().range([height2, 10]);
var xAxis = d3.svg.axis().scale(x).orient("bottom"),
xAxis2 = d3.svg.axis().scale(x2).orient("bottom"),
yAxis = d3.svg.axis().scale(y).orient("left");
var brush = d3.svg.brush()
.x(x2)
.on("brush", brush);
var area = d3.svg.area()
.interpolate("monotone")
.x(function(d) { return x(format.parse(d3.keys(d)[0])); })
.y0(height)
.y1(function(d) { return y(d3.values(d)[0]); });
var area2 = d3.svg.area()
.interpolate("monotone")
.x(function(d) { return x2(format.parse(d3.keys(d)[0])); })
.y0(height2)
.y1(function(d) { return y2(d3.values(d)[0]); });
var svg = d3.select("body").append("svg")
.attr("width", width + margin.left + margin.right)
.attr("height", height + margin.top + margin.bottom);
svg.append("defs").append("clipPath")
.attr("id", "clip")
.append("rect")
.attr("width", width)
.attr("height", height);
var focus = svg.append("g")
.attr("transform", "translate(" + margin.left + "," + margin.top + ")");
var context = svg.append("g")
...