{
const width = 900;
const height = 300;
const marginTop = 25;
const marginRight = 20;
const marginBottom = 35;
const marginLeft = 40;
const x = d3
.scaleUtc()
.domain(d3.extent(appleStockData, (d) => d.Date))
.nice()
.range([0, width]);
const bandScale = d3
.scaleBand()
.domain(Array.from(new Set(appleStockData.map((d) => d.Date))))
.range([0, width]);
const y = d3
.scaleLinear()
.domain(d3.extent(appleStockData, (d) => d.Close))
.nice()
.range([height, 0]);
const svg = d3
.create("svg")
.attr("width", width + marginLeft + marginRight)
.attr("height", height + marginTop + marginBottom);
const g = svg
.append("g")
.attr("transform", `translate(${marginLeft}, ${marginTop})`);
g.append("g")
.attr("transform", `translate(0,${height})`)
.call(d3.axisBottom(x).ticks(width / 80));
g.append("g").call(d3.axisLeft(y));
g.append("g")
.attr("fill", "steelblue")
.selectAll("rect")
.data(appleStockData)
.join("rect")
.attr("x", (d) => x(d.Date))
.attr("y", (d) => y(d.Close))
.attr("width", bandScale.bandwidth())
.style("opacity", 0.5)
.attr("height", (d) => height - y(d.Close));
g.append("g")
.attr("fill", "#000")
.selectAll("circle")
.data(appleStockData)
.join("circle")
.attr("cx", (d) => x(d.Date))
.attr("cy", (d) => y(d.Close))
.attr("r", 2);
return svg.node();
}