chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append('defs').append('clipPath')
.attr('id', 'barGroup_clip')
.append('rect')
.attr('transform', `translate(${margin.left}, ${margin.top})`)
.attr('width', width - margin.left - margin.right)
.attr('height', height - margin.top - margin.bottom);
svg.append("g")
.attr('id', 'barGroup')
.attr("fill", "steelblue")
.style('clip-path', 'url(#barGroup_clip)')
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => margin.left + (barWidth + 3) * i)
.attr("y", d => y(d.value))
.attr("height", d => y(0) - y(d.value))
.attr("width", barWidth);
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
const anchorIdx = Math.round((width - margin.left - margin.right) / (barWidth + 3)) - 1;
const brushGroup = svg.append('g')
.attr('class', 'brush')
.attr('transform', `translate(${margin.left}, ${height - margin.bottom})`)
.call(brush)
.call(brush.move, [0, x2(data[anchorIdx].name)]);
brushGroup.selectAll('rect').attr('height', brushHeight);
return svg.node();
}