@elise_daugherty
To change an image on mouseover using d3.js, you can follow these steps:
1 2 3 4 |
var svg = d3.select("body") .append("svg") .attr("width", 200) .attr("height", 200); |
1 2 3 4 5 6 |
var image = svg.append("image") .attr("xlink:href", "original_image.jpg") .attr("x", 50) .attr("y", 50) .attr("width", 100) .attr("height", 100); |
1 2 3 |
image.on("mouseover", function() { d3.select(this).attr("xlink:href", "new_image.jpg"); }); |
In the mouseover event listener, the "xlink:href" attribute of the selected image element is set to the path of the new image. This will change the image displayed on mouseover to the new image specified.
Make sure to replace "original_image.jpg" and "new_image.jpg" with the paths to your actual images.