chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const defs = svg.append("defs");
const reverseGradient = defs
.append("linearGradient")
.attr("id", "reverse-gradient");
reverseGradient
.append("stop")
.attr('offset', '20%')
.attr('stop-color', 'gray')
.attr('stop-opacity', '100%');
reverseGradient
.append("stop")
.attr('offset', '60%')
.attr('stop-color', 'gray')
.attr('stop-opacity', '0%');
const linearGradient = defs
.append("linearGradient")
.attr("id", "forecast-gradient");
linearGradient
.append("stop")
.attr('offset', '20%')
.attr('stop-color', 'gray')
.attr('stop-opacity', '0%');
linearGradient
.append("stop")
.attr('offset', '60%')
.attr('stop-color', 'gray')
.attr('stop-opacity', '100%');
defs
.append('rect')
.attr('id', 'gradient-rect')
.attr('width', '100%')
.attr('height', '100%')
.attr('fill', "url('#forecast-gradient')");
const filter = defs.append("filter").attr("id", 'forecast-filter');
filter
.append("feGaussianBlur")
.attr("in", "SourceGraphic")
.attr("stdDeviation", exStdDev)
.attr("color-interpolation-filters", "sRGB");
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
const g = svg
.append("g")
.attr("fill", "none")
.attr("stroke-linejoin", "round")
.attr("stroke-linecap", "round");
g.selectAll("path")
.data(dataGrouped)
.join("path")
.attr("stroke", 'url(#reverse-gradient)')
.attr("stroke-width", .5)
.attr("d", line)
.call(halo);
g.append('g')
.selectAll("path")
.data(dataGrouped)
.join("path")
.attr("stroke", 'url(#forecast-gradient)')
.attr("stroke-width", 3)
.attr("filter", "url('#forecast-filter')")
.attr("d", line)
.call(halo);
g.append("path")
.datum(dataActual)
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("d", line);
g.selectAll("text")
.data(dataGrouped.map(d => d[d.length - 1]))
.join("text")
.attr("fill", "gray")
.attr("font-size", 10)
.attr("font-family", "sans-serif")
.attr("dx", 4)
.attr("dy", ".3em")
.attr("x", ({ about }) => x(about))
.attr("y", ({ value }) => y(value))
.text(({ on }) => dateFormat(on));
return svg.node();
}