Now I want to go a little further and figure how to insert a line
break in the text element in the tooltip. I would appreciate if
someone could help with that. I tried inserting "\n" in .text(), but
that does not help (please see the body of function mousemove()
below). The following is a working example.
Thanks in advance for your help.
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript"
src="http://mbostock.github.com/d3/d3.js"></script>
<style type="text/css">
div.tooltip {
position: absolute;
text-align: center;
z-index: 10;
width: 100px;
height: 24px;
padding: 8px;
font: 24px sans-serif;
background: red;
color: white;
border: solid 1px #aaa;
border-radius: 8px;
opacity: 0;
}
</style>
</head>
<body>
<div id="viz"></div>
<script type="text/javascript">
canvas = d3.select("#viz")
.append("svg:svg")
.attr("width", 400)
.attr("height", 400);
canvas.append("svg:rect")
.attr("x", 20)
.attr("y", 20)
.attr("width", 200)
.attr("height", 200)
.style("stroke", "gray")
.style("fill-opacity", 0.5)
.on("mouseover", mouseover)
.on("mousemove", mousemove)
.on("mouseout", mouseout);
tooltipdiv = d3.select("body")
.append("div")
.attr("class", "tooltip");
circle = d3.select("body")
.append("svg:svg")
.append("svg:circle")
.style("stroke", "red")
.style("fill", "blue")
function mouseover(){
tooltipdiv
.style("visibility", "visible")
.style("opacity", 1);
}
function mousemove(){
tooltipdiv
.style("visibility", "visible")
.style("opacity", 0.5)
.style("top", d3.event.pageY + "px")
.style("left", d3.event.pageX + "px")
.text(d3.event.pageX + "\n line"); /* \n does not work in
creating a line break*/
}
function mouseout(){
tooltipdiv.style("opacity", 0.5)
.style("visibility", "hidden");
}
</script>
</body>
</html>
As this is a classical html div, br, p... Will do the trick.
Send from my mobile
.html(d3.event.pageX + "<br\/> line");
There is no need to escape the slash character. It works with that.
--
You received this message because you are subscribed to the Google Groups "d3-js" group.
To unsubscribe from this group and stop receiving emails from it, send an email to d3-js+un...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.