{
const width = 400;
const height = 200;
const container = d3.create('svg')
.attr('width', width)
.attr('height', height);
const xscale = d3.scaleBand()
.domain(barData.map(d => d.key))
.range([0, width]);
const yscale = d3.scaleLinear()
.domain([d3.max(barData, d => d.value), 0])
.range([height, 0]);
container.selectAll('rect')
.data(barData)
.join('rect')
.attr('x', d => xscale(d.key))
.attr('y', d => height-yscale(d.value))
.attr('width',xscale.bandwidth())
.attr('height', d => yscale(d.value))
.style('fill', d => color(d.key))
.style('stroke', 'white');
container.selectAll('text')
.data(barData)
.join('text')
.attr('x', d => xscale(d.key))
.attr('y', d => height - yscale(d.value))
.attr('dx', 33)
.attr('dy', 30)
.attr('fill', 'white')
.style('font-size', 'small')
.style('text-anchor', 'middle')
.text(d => d.value);
return container.node();
}