emissions_chart = {
const margin = { top: 10, bottom: 50, right: 10, left: 80 };
const visHeight = 500 - margin.top - margin.bottom;
const visWidth = width - margin.left - margin.right;
const svg = d3.create('svg')
.attr('width', visWidth + margin.left + margin.right)
.attr('height', visHeight + margin.top + margin.bottom);
const g = svg.append('g')
.attr('transform', `translate(${margin.left}, ${margin.top})`);
const x = d3.scaleLinear()
.domain([1990.00,2019.00])
.range([0, visWidth]);
const y = d3.scaleLinear()
.domain([0, maxEmissions]).nice()
.range([visHeight, 0]);
const xAxis = d3.axisBottom(x);
const yAxis = d3.axisLeft(y);
g.append('g')
.attr('transform', `translate(0,${visHeight})`)
.call(xAxis);
g.append('g')
.call(yAxis)
.call(g => g.selectAll('.domain').remove())
.append('text')
.attr('text-anchor', 'start')
.attr('dominant-baseline', 'middle')
.attr('fill', 'black')
.attr('x', 5)
.text('Emissions - tonnes');
const line = d3.line()
.x(d => x(d.Year))
.y(d => y(d["Annual CO2 emissions"]));
const series = g.append('g')
.selectAll('g')
.data(dataByCountry)
.join('g')
.attr('stroke', d => color(d.country))
.append('path')
.datum(d => d.counts)
.attr('fill', 'none')
.attr('stroke-width', 2)
.attr('d', line);
g.append("text")
.attr("x", visWidth / 4 * 3 - 70)
.attr("y", (margin.bottom + 425))
.attr("text-anchor", "right")
.attr("dominant-baseline", "hanging")
.attr("font-family",'Source Serif Pro')
.attr("font-size", "12px")
.text("Source: Our World in Data - CO2 Emissions");
return svg.node()
}