chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const path = svg.append("path")
.attr("d", line(data))
.attr("fill", "none")
.attr("stroke-width", 4)
.attr("stroke-dasharray", 8 + " " + 4)
.attr("stroke", "darkgrey")
.on('mouseover', animateDash)
.on('mouseout', staticDash)
const length = path.node().getTotalLength();
function animateDash() {
path.attr("stroke-dasharray", 8 + " " + 50)
.attr("stroke-dashoffset", length)
.transition()
.ease(d3.easeLinear)
.attr("stroke-dashoffset", 0)
.duration(6000)
.on("end", () => setTimeout(animateDash, 1));
}
function staticDash() {
path.attr("stroke-dasharray", 8 + " " + 4)
}
return svg.node();
}