chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const rect = svg
.selectAll('g')
.data(data)
.enter()
.append('rect')
.attr('fill', staticColor)
.attr('x', (d, i) => x(d.country))
.attr('width', x.bandwidth())
.attr('y', d => y(0))
.attr('height', d => height - y(0))
.on('mouseover', function (d, i) {
tooltip
.html(
`<div>Country: ${d.country}</div><div>Value: ${d.value}</div>`
)
.style('visibility', 'visible');
d3.select(this).transition().attr('fill', hoverColor);
})
.on('mousemove', function () {
tooltip
.style('top', d3.event.pageY - 10 + 'px')
.style('left', d3.event.pageX + 10 + 'px');
})
.on('mouseout', function () {
tooltip.html(``).style('visibility', 'hidden');
d3.select(this).transition().attr('fill', staticColor);
});
rect
.transition()
.ease(d3.easeLinear)
.duration(800)
.attr('y', d => y(d.value))
.attr('height', d => height - y(d.value))
.delay((d, i) => i * 100);
return svg.node();
}