プロット領域を入力してそのポイントのツールチップを表示すると、マウスに最も近いポイントを見つけることができます。
this great postを読んで、すばらしいツールチップを作成する方法をよく説明してください。 上記のポストはポイント上にテキストを表示しませんが、ロジックはあなたがしたいこととまったく同じです。重要なコードは次のとおりです。
// append the rectangle to capture mouse
svg.append("rect")
.attr("width", width)
.attr("height", height)
.style("fill", "none")
.style("pointer-events", "all")
.on("mouseover", function() { focus.style("display", null); })
.on("mouseout", function() { focus.style("display", "none"); })
.on("mousemove", mousemove);
function mousemove() {
var x0 = x.invert(d3.mouse(this)[0]),
i = bisectDate(data, x0, 1),
d0 = data[i - 1],
d1 = data[i],
d = x0 - d0.date > d1.date - x0 ? d1 : d0;
//you may want to change that to select a text area rather than a circle - whatever object is your tooltip in your code
focus.select("circle.y")
.attr("transform",
"translate(" + x(d.date) + "," +
y(d.close) + ")");
}