{
const height = width / 1.6;
const margin = {top: 20, right: 30, bottom: 50, left: 40};
const x = d3.scaleTime()
.domain(d3.extent(data, d => d.date))
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain([0, d3.max(data, d => d.close)]).nice()
.range([height - margin.bottom, margin.top]);
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const area = d3.area()
.curve(d3.curveBasis)
.x(d => x(d.date))
.y1(d => y(d.close))
.y0(d => y(0));
const gradient = svg.append("defs").append("linearGradient")
.attr("id", "mygrad")
.attr("x1", "0%")
.attr("x2", "0%")
.attr("y1", "0%")
.attr("y2", "100%");
gradient.append("stop")
.attr("offset", "0%")
.style("stop-color", "#002EEE")
.style("stop-opacity", 0.7);
gradient.append("stop")
.attr("offset", "100%")
.style("stop-color", "white")
.style("stop-opacity", 0.1)
svg.append("path")
.datum(data)
.attr("d", area)
.style("fill", "url(#mygrad)");
const line = d3.line()
.curve(d3.curveBasis)
.x(d => x(d.date))
.y(d => y(d.close));
svg.append("path")
.datum(data)
.attr("fill", "none")
.attr("stroke", "#002EEE")
.attr("stroke-width", 5)
.attr("d", line);
const xAxisGenerator = d3.axisBottom(x)
.tickPadding(20)
.tickSizeInner(0);
const yAxisGenerator = d3.axisLeft(y)
.ticks(4)
.tickSizeInner(-width+margin.right+margin.left);
const xAxis = svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(xAxisGenerator);
const yAxis = svg.append("g")
.attr("transform", `translate(${margin.left},0)`)
.call(yAxisGenerator)
yAxis.select(".domain").remove();
yAxis.selectAll("line")
.attr("stroke", "#000")
.attr("stroke-opacity", "0.04");
yAxis.selectAll("text")
.attr("font-size", 14)
.attr("font-weight", "bold")
.attr("fill", "#7B7B7B");
xAxis.select(".domain").remove();
xAxis.selectAll("text")
.attr("font-size", 14)
.attr("font-weight", "bold")
.attr("fill", "#7B7B7B");
return svg.node();
}