barchart= {
const w = 900;
const h = 400;
const margin = ({top: 10, right: 10, bottom: 5, left: 20})
let dataset = [];
for (let i = 0; i < numBars; ++i) {
let randomNum = Math.random() * h;
dataset.push(randomNum)
};
let svg = d3.create("svg")
.attr("width", w)
.attr("height", h)
.style("background-color", colorBg)
let xScale = d3.scaleBand()
.domain(d3.range(dataset.length))
.range([margin.left, w - margin.right])
.paddingInner(0.05);
let yScale = d3.scaleLinear()
.domain([0, d3.max(dataset)])
.range([h - margin.bottom, margin.top]);
svg.selectAll("rect")
.data(dataset)
.join("rect")
.attr("x", (d, i) => xScale(i))
.attr("y", d => yScale(d))
.attr("width", xScale.bandwidth())
.attr("height", d => h - margin.bottom - yScale(d))
.style("fill", colorBars);
d3.select(newData)
.on("click", function() {
dataset = [];
for (let i = 0; i < numBars; ++i) {
let randomNum = Math.random() * h;
dataset.push(randomNum)
};
xScale.domain(d3.range(dataset.length))
yScale.domain([0, d3.max(dataset)])
svg.selectAll("rect")
.data(dataset)
.transition()
.duration(1000)
.attr("x", (d, i) => xScale(i))
.attr("y", d => yScale(d))
.attr("width", xScale.bandwidth())
.attr("height", d => h - margin.bottom - yScale(d))
})
return svg.node()
}