chart = {
const chart = DOM.svg(800, 500);
const svg = d3.select(chart);
const width = +svg.attr("width");
const height = +svg.attr("height");
const xValue = d => d.date.value;
const yValue = d => d.population.value;
const margin = { top: 30, right: 20, bottom:60, left: 70 };
const innerWidth = width - margin.left - margin.right;
const innerHeight = height - margin.top - margin.bottom;
const xScale = d3.scaleUtc()
.domain(d3.extent(data, xValue))
.range([0, innerWidth])
.nice();
const yScale = d3.scaleLinear()
.domain(d3.extent(data, yValue))
.range([innerHeight, 0])
.nice();
const g = svg.append("g")
.attr("transform", `translate(${margin.left},${margin.top})`)
const xAxis = d3.axisBottom(xScale)
.tickSize(-innerHeight)
.tickPadding(10);
const yAxis = d3.axisLeft(yScale)
.tickSize(-innerWidth);
const yAxisG = g.append("g").call(yAxis);
yAxisG.selectAll(".domain")
.remove();
yAxisG.append("text")
.attr("x", -innerHeight / 2)
.attr("y", -60 )
.attr("text-anchor", "middle")
.attr("fill", "black")
.text("Population")
.attr("transform", "rotate(-90)")
.attr("class", "yAxisLabel");
const xAxisG = g.append("g").call(xAxis)
.attr("transform", `translate(0,${innerHeight})`);
xAxisG.select(".domain").remove();
xAxisG.append("text")
.attr("x", innerWidth / 2)
.attr("y", 40)
.attr("fill", "black")
.text("Year")
.attr("class", "xAxisLabel");
const lineGenerator = d3.line()
.x(d => xScale(xValue(d)))
.y(d => yScale(yValue(d)));
g.append("path")
.attr("class", "line-path")
.attr("d", lineGenerator(data));
g.selectAll("circle")
.data(data)
.enter()
.append("circle")
.attr("cx", d => xScale(xValue(d)))
.attr("cy", d => yScale(yValue(d)))
.attr("r", 4)
.append("title").text(function(d) { return `${xValue(d).getFullYear()}: ${yValue(d)}` } );
g.append("text")
.attr("x", 40)
.attr("y", -10)
.text(`Line chart of United Kingdom population by year`);
return chart;
}