{
const width = 300;
const height = 200;
const marginTop = 20;
const marginRight = 30;
const marginBottom = 30;
const marginLeft = 60;
const color = d3.scaleOrdinal()
.domain(data.map(d => d.name))
.range(d3.schemeObservable10);
const x = d3.scaleLinear()
.domain([0, d3.max(data, d => d.value)])
.range([marginLeft, width - marginRight]);
const y = d3.scaleBand()
.domain(data.map(d => d.name))
.range([marginTop, height - marginBottom])
.padding(0.1);
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [0, 0, width, height])
.attr("style", "max-width: 100%; height: auto;");
svg.append("g")
.selectAll("rect")
.data(data)
.join("rect")
.attr("x", marginLeft)
.attr("y", d => y(d.name))
.attr("height", y.bandwidth())
.attr("width", d => x(d.value) - x(0))
.style("fill", d => color(d.name));
svg.append("g")
.attr("transform", `translate(0,${height - marginBottom})`)
.call(d3.axisBottom(x).ticks(5))
svg.append("g")
.attr("transform", `translate(${marginLeft},0)`)
.call(d3.axisLeft(y));
return svg.node();
}