chart = {
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
svg.append("g")
.attr("fill", color)
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", (d, i) => x(i))
.attr("y", d => y(d.value))
.attr("height", d => y(0) - y(d.value))
.attr("width", x.bandwidth())
.on('mouseover', function (e, d, i) {
tooltip
.html(
`<div>Country: ${d.name}</div><div>Value: ${d.value}</div>`
)
.style('visibility', 'visible');
d3.select(this).transition().attr('fill', '#000000');
})
.on('mousemove', function (e) {
tooltip
.style('top', e.pageY - 10 + 'px')
.style('left', e.pageX + 10 + 'px');
})
.on('mouseout', function (e) {
tooltip.html(``).style('visibility', 'hidden');
d3.select(this).transition().attr('fill', color);
});
svg.append("g")
.call(xAxis);
svg.append("g")
.call(yAxis);
return svg.node();
}