chart = {
const width = 928;
const height = 500;
const marginTop = 20;
const marginRight = 30;
const marginBottom = 30;
const marginLeft = 40;
const aapl2 =aapl.slice(0,30)
const x = d3.scaleUtc(d3.extent(aapl2, d => d.date), [marginLeft, width - marginRight]);
const y = d3.scaleLinear([0, d3.max(aapl2, d => d.close)], [height - marginBottom, marginTop]);
const area = d3.area()
.x(d => x(d.date))
.y0(y(0))
.y1(d => y(d.close));
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("path")
.attr("fill", "steelblue")
.attr("d", area(aapl2));
svg.append("path")
.datum(aapl2)
.attr("fill", "none")
.attr("stroke", "#69b3a2")
.attr("stroke-width", 4)
.attr("d", d3.line()
.x(function(d) { return x(d.date) })
.y(function(d) { return y(d.close) })
)
svg.append("g")
.attr("transform", `translate(0,${height - marginBottom})`)
.call(d3.axisBottom(x).ticks(width / 80).tickSizeOuter(0));
svg.selectAll("myCircles")
.data(aapl2)
.enter()
.append("circle")
.attr("fill", "black")
.attr("stroke", "none")
.attr("cx", function(d) { return x(d.date) })
.attr("cy", function(d) { return y(d.close) })
.attr("r", 4)
svg.selectAll("myCircles")
.data(aapl2)
.enter()
.append("circle")
.attr("fill", "red")
.attr("stroke", "none")
.attr("cx", function(d) { return x(d.date) })
.attr("cy", function(d) { return y(d.close) })
.attr("r", 2)
svg.selectAll("myCircles")
.data(aapl2.slice(-1))
.enter()
.append("circle")
.attr("fill", "blue")
.attr("stroke", "none")
.attr("cx", function(d) { return x(d.date) })
.attr("cy", function(d) { return y(d.close) })
.attr("r", 4)
svg.append("g")
.attr("transform", `translate(${marginLeft},0)`)
.call(d3.axisLeft(y).ticks(height / 40))
.call(g => g.select(".domain").remove())
.call(g => g.selectAll(".tick line").clone()
.attr("x2", width - marginLeft - marginRight)
.attr("stroke-opacity", 0.1))
.call(g => g.append("text")
.attr("x", -marginLeft)
.attr("y", 10)
.attr("fill", "currentColor")
.attr("text-anchor", "start")
.text("↑ Daily close ($)"));
return svg.node();
}