chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.attr("font-family", "sans-serif")
.attr("font-size", 10)
.attr("stroke-miterlimit", 1);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
svg.append("g")
.call(grid);
svg.append("path")
.attr("fill", "steelblue")
.attr("fill-opacity", 0.2)
.attr("d", area(data));
svg.append("path")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("d", line(data.slice(0, observedIndex + 1)));
svg.append("path")
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("stroke-dasharray", "3,3")
.attr("d", line(data.slice(observedIndex)));
svg.append("circle")
.attr("cx", x(observed.date))
.attr("cy", y(observed.mean))
.attr("r", 2.5);
svg.append("text")
.attr("x", x(observed.date))
.attr("y", y(observed.mean))
.attr("dx", 6)
.attr("dy", "0.35em")
.text(observed.mean.toLocaleString("en"));
svg.append("text")
.attr("x", x(observed.date))
.attr("y", y(observed.mean))
.attr("dx", 6)
.attr("dy", "1.35em")
.text(d3.utcFormat("%B %-d")(observed.date));
return svg.node();
}