This concise example demonstrates common way how to create custom tooltip in d3.
var w = 500;_x000D_
var h = 150;_x000D_
_x000D_
var dataset = [5, 10, 15, 20, 25];_x000D_
_x000D_
// firstly we create div element that we can use as_x000D_
// tooltip container, it have absolute position and_x000D_
// visibility: hidden by default_x000D_
_x000D_
var tooltip = d3.select("body")_x000D_
.append("div")_x000D_
.attr('class', 'tooltip');_x000D_
_x000D_
var svg = d3.select("body")_x000D_
.append("svg")_x000D_
.attr("width", w)_x000D_
.attr("height", h);_x000D_
_x000D_
// here we add some circles on the page_x000D_
_x000D_
var circles = svg.selectAll("circle")_x000D_
.data(dataset)_x000D_
.enter()_x000D_
.append("circle");_x000D_
_x000D_
circles.attr("cx", function(d, i) {_x000D_
return (i * 50) + 25;_x000D_
})_x000D_
.attr("cy", h / 2)_x000D_
.attr("r", function(d) {_x000D_
return d;_x000D_
})_x000D_
_x000D_
// we define "mouseover" handler, here we change tooltip_x000D_
// visibility to "visible" and add appropriate test_x000D_
_x000D_
.on("mouseover", function(d) {_x000D_
return tooltip.style("visibility", "visible").text('radius = ' + d);_x000D_
})_x000D_
_x000D_
// we move tooltip during of "mousemove"_x000D_
_x000D_
.on("mousemove", function() {_x000D_
return tooltip.style("top", (event.pageY - 30) + "px")_x000D_
.style("left", event.pageX + "px");_x000D_
})_x000D_
_x000D_
// we hide our tooltip on "mouseout"_x000D_
_x000D_
.on("mouseout", function() {_x000D_
return tooltip.style("visibility", "hidden");_x000D_
});
_x000D_
.tooltip {_x000D_
position: absolute;_x000D_
z-index: 10;_x000D_
visibility: hidden;_x000D_
background-color: lightblue;_x000D_
text-align: center;_x000D_
padding: 4px;_x000D_
border-radius: 4px;_x000D_
font-weight: bold;_x000D_
color: orange;_x000D_
}
_x000D_
<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/4.11.0/d3.min.js"></script>
_x000D_