chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
svg.append("g")
.selectAll("path")
.data(series)
.join("path")
.attr("fill", ({key}) => areaColor(key))
.attr("d", area)
.append("title")
.text(({key}) => key + '%');
svg.append("g")
.attr("class", "grid")
.attr("transform", `translate(${margin.left},0)`)
.attr("stroke", "lightgrey")
.attr("stroke-opacity", "0.3")
.attr("stroke-width", ".3")
.attr("shape-rendering", "crispEdges")
.call(make_y_gridlines()
.tickSize(-width + margin.left + margin.right)
.tickFormat("")
)
dataNest.forEach(function(d,i) {
svg.append("path")
.attr("class", "line")
.style("stroke", function() {
return d.color = lineColor(d.key); })
.style("fill", "none")
.style("stroke-width", "3px")
.attr("id", 'tag'+d.key.replace(/\s+/g, ''))
.attr("d", priceline(d.values))
.append("title")
.text(d.key + '%');
});
let x_axis = svg.append("g")
.attr("id", "x-axis")
.attr("class", "x axis")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(xAxis);
setTickFormatX(period);
if (['H','D','W','M'].includes(period)) {
x_axis.selectAll("text")
.style("text-anchor", "end")
.attr("dx", "-.8em")
.attr("dy", ".15em")
.attr("transform", "rotate(-45)");
}
svg.append("g")
.attr("class", "y axis")
.call(yAxis);
return svg.node();
}