chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
const g = svg.append("g").attr("transform", "translate(" + margin.left + "," + margin.top + ")");
let path = svg.selectAll("path.dataline")
.data(select_States)
.enter()
.append("path")
.attr("class", "dataline")
.attr("fill", "none")
.attr("stroke", d => colors(d))
.attr("stroke-width", 1.5)
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round")
.attr("d", state => line(casesByState.get(state)));
const legend = g.append("g")
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("text-anchor", "end")
.attr("transform", "translate(0,20)")
.selectAll("g")
.data(select_States)
.enter().append("g")
.attr("transform", function(d, i) {
return "translate(0," + i * 20 + ")";
});
legend.append("rect")
.attr("x", 10)
.attr("width", 18)
.attr("height", 18)
.attr("fill", d => colors(d));
legend.append("text")
.attr("x", 35)
.attr("y", 12)
.attr("dy", "0.32em")
.attr("text-anchor", "start")
.text(function(d) {
return d;
});
return svg.node();
}