chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width + 50, height]);
const yLabel = svg.append("g").call(yTitle);
const xgridlines = svg.append("g").call(xGrid);
const ygridlines = svg.append("g").call(yGrid);
svg
.selectAll('path')
.data(data)
.join('path')
.attr('class', 'stock-lines')
.attr('d', line)
.style('stroke', (d, i) => colors(d[i].name))
.style('stroke-width', 2)
.style('fill', 'transparent');
svg
.append('g')
.attr('class', 'x-axis')
.attr('transform', `translate(0,${height - margin.bottom})`)
.call(xAxis);
svg
.append('g')
.attr('class', 'y-axis')
.attr('transform', `translate(${margin.left},0)`)
.call(yAxis)
.selectAll('.domain')
.remove();
svg
.selectAll('text.label')
.data(data)
.join('text')
.attr('class', 'label')
.attr('x', width - margin.right + 5)
.attr(
'y',
d => yScale(d[d.length - 1].value) + (d[0].name === 'BABA' ? -12 : 0)
)
.attr('dy', '0.35em')
.style('fill', d => colors(d[0].name))
.style('font-family', 'sans-serif')
.style('font-size', 12)
.text(d => d[0].name);
return svg.node();
}