chart = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("overflow", "visible");
const x = d3
.scaleLinear()
.domain(d3.extent(Diamonds, (d) => d.carat))
.range([margin.left, width - margin.right]);
const c = d3
.scaleLinear()
.domain(d3.extent(Diamonds, (d) => d.price))
.range(["#662e9b", "#06d6a0"]);
const y = d3
.scaleLinear()
.domain(d3.extent(Diamonds, (d) => d.price))
.rangeRound([height - margin.bottom, margin.top]);
svg
.selectAll("circle")
.data(Diamonds)
.join("circle")
.style("fill", (d) => c(d.price))
.attr("cx", (d) => x(d.carat))
.attr("cy", (d) => y(d.price))
.attr("r", (d) => d.carat);
let xaxis = svg
.append("g")
.attr("class", "x-axis")
.attr("transform", `translate(0, ${height - margin.bottom})`)
.call(d3.axisBottom().scale(x).ticks(5).tickSize(-height).tickPadding(15));
let formatNumber = d3.format(".2s");
let yaxis = svg
.append("g")
.attr("class", "y-axis")
.attr("transform", `translate(40,0)`)
.call(
d3
.axisLeft()
.scale(y)
.tickValues([
1000, 2000, 4000, 6000, 8000, 10000, 12000, 14000, 16000, 18000
])
.tickSize(-width)
.tickPadding(15)
.tickFormat(formatNumber)
);
return svg.node();
}