chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
svg.append("g")
.selectAll("g")
.data(series)
.enter().append("g")
.attr("fill", d => color(d.key))
.attr("data-legend", d => d.key)
.selectAll("rect")
.data(d => d)
.enter().append("rect")
.attr("width", x.bandwidth)
.attr("x", d => x(new Date(d.data.fordate)))
.attr("y", d => y(d[1]))
.attr("height", d => y(d[0]) - y(d[1]))
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis)
const legend = svg.selectAll('.legend')
.data(color.domain())
.enter()
.append('g')
.attr('class', 'legend')
.attr('transform', (d, i) => {
let legendHeight = legendRectSize + legendSpacing;
let x = width - margin.right;
let y = i * legendHeight + margin.top;
return `translate(${x}, ${y})`;
});
legend.append('rect')
.attr('width', legendRectSize)
.attr('height', legendRectSize)
.style('fill', color)
.style('stroke', color);
legend.append('text')
.attr('x', legendRectSize + legendSpacing)
.attr('y', legendRectSize)
.text(d => d);
return svg.node();
}