meusvg = function (arr) {
const margem = { left: 30, top: 30, bottom: 0, right: 30 };
const size = { width: 500, height: 300 };
let grafico = d3
.create("svg")
.attr("width", size.width + margem.left + margem.right)
.attr("height", size.height + margem.top + margem.bottom);
let y = d3
.scaleLinear()
.domain(d3.extent(arr))
.range([size.height - margem.top, 0]);
let x = d3.scaleLinear().domain([0, 11]).range([0, size.height]);
let g = grafico
.append("g")
.attr("transform", `translate(${margem.left},${margem.top})`);
grafico
.append("g")
.attr("transform", `translate(${margem.left},${margem.top})`)
.call(d3.axisLeft(y));
grafico
.append("g")
.attr("transform", `translate(${margem.left},${margem.top})`)
.call(d3.axisTop(x));
g.selectAll(".barra")
.data(arr)
.join(
(enter) =>
enter
.append("rect")
.attr("x", (d, i) => x(i))
.attr("fill", "#000000")
.attr("width", 20)
.attr("y", (d) => size.height - margem.top - y(300))
.attr("height", 0)
.transition()
.duration(3000)
.attr("y", (d) => y(d))
.attr("height", (d) => size.height - margem.top - y(d)),
(update) =>
update
.append("rect")
.attr("x", (d, i) => x(i))
.attr("fill", "#000000")
.attr("width", 20)
.attr("y", (d) => y(d))
.attr("height", (d) => size.height - margem.top - y(d)),
(exit) =>
exit
.append("rect")
.attr("x", (d, i) => x(i))
.attr("fill", "#000000")
.attr("width", 20)
.attr("y", (d) => y(d3.extent(arr)[1]))
.attr("height", (d) => 0)
);
return grafico.node();
}