chart = {
const svg = d3.create('svg')
.attr('viewBox', [0, 0, width, height])
.call(addWebFont, 'Lato', 'https://fonts.gstatic.com/s/lato/v16/S6uyw4BMUTPHjx4wXiWtFCc.woff2')
.call(addWebFont, 'Lato-Bold', 'https://fonts.gstatic.com/s/lato/v16/S6u9w4BMUTPHh6UVSwiPGQ3q5d0.woff2')
.attr('style', `
background-color: ${background};
font-family: 'Lato';
`);
svg.append('linearGradient')
.attr('id', 'temperature-gradient')
.attr('gradientUnits', 'userSpaceOnUse')
.attr('x1', x(1)).attr('y1', 0)
.attr('x2', x(3)).attr('y2', 0)
.selectAll('stop')
.data([
{offset: '0%', color: gradient1 },
{offset: '100%', color: gradient2 },
])
.enter().append('stop')
.attr('offset', function(d) { return d.offset; })
.attr('stop-color', function(d) { return d.color; });
svg.append('path')
.datum(data2)
.attr('fill', 'url(#temperature-gradient)')
.attr('d', area);
svg.append('path')
.datum(data2)
.attr('fill', 'url(#temperature-gradient)')
.attr('d', areaMirror);
svg.selectAll('.values')
.data(data)
.enter()
.append('text')
.attr('class', 'values')
.attr('x', ({ step }) => x(step) + 10)
.attr('y', 30)
.text(({ value }) => d3.format(',')(value))
.attr('style', `
fill: ${values};
font-size: 22px;
`);
svg.selectAll('.labels')
.data(data)
.enter()
.append('text')
.attr('class', 'labels')
.attr('x', ({ step }) => x(step) + 10)
.attr('y', 50)
.text(({ label }) => label)
.attr('style', `
fill: ${labels};
font-family: 'Lato-Bold';
font-size: 14px;
`);
svg.selectAll('.percentages')
.data(data)
.enter()
.append('text')
.attr('class', 'percentages')
.attr('x', ({ step }) => x(step) + 10)
.attr('y', 70)
.text(({ value }, index) => index === 0 ? '' : d3.format('.1%')(value / data[0].value))
.attr('style', `
fill: ${percentages};
font-size: 18px;
`);
svg.selectAll('line')
.data(d3.range(2, data.length + 1))
.enter()
.append('line')
.attr('x1', value => x(value))
.attr('y1', 10)
.attr('x2', value => x(value))
.attr('y2', height - 30)
.style('stroke-width', 1)
.style('stroke', percentages)
.style('fill', 'none');
return svg.node();
}