Created
March 22, 2016 11:53
-
-
Save martinnormark/e00236af5402f6d22dec to your computer and use it in GitHub Desktop.
Adding a vertical line to a D3 chart, that follows the mouse pointer.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var vertical = d3.select(".chart") | |
.append("div") | |
.attr("class", "remove") | |
.style("position", "absolute") | |
.style("z-index", "19") | |
.style("width", "1px") | |
.style("height", "380px") | |
.style("top", "10px") | |
.style("bottom", "30px") | |
.style("left", "0px") | |
.style("background", "#fff"); | |
d3.select(".chart") | |
.on("mousemove", function(){ | |
mousex = d3.mouse(this); | |
mousex = mousex[0] + 5; | |
vertical.style("left", mousex + "px" )}) | |
.on("mouseover", function(){ | |
mousex = d3.mouse(this); | |
mousex = mousex[0] + 5; | |
vertical.style("left", mousex + "px")}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment