viewof lineChart = {
const width = 800, height = 400;
const margin = { top: 40, right: 100, bottom: 40, left: 60 };
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);
const x = d3.scaleLinear()
.domain(d3.extent(years, d => +d))
.range([margin.left, width - margin.right]);
const y = d3.scaleLinear()
.domain([0, d3.max(lineData, d => d3.max(d.values, v => v.value))]).nice()
.range([height - margin.bottom, margin.top]);
const color = d3.scaleOrdinal()
.domain(selectedCountries)
.range(d3.schemeTableau10);
const xAxis = g => g
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).tickFormat(d3.format("d")));
const yAxis = g => g
.attr("transform", `translate(${margin.left},0)`)
.call(d3.axisLeft(y));
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
const line = d3.line()
.x(d => x(d.year))
.y(d => y(d.value));
svg.selectAll(".line")
.data(lineData)
.join("path")
.attr("fill", "none")
.attr("stroke", d => color(d.country))
.attr("stroke-width", 2)
.attr("d", d => line(d.values));
svg.selectAll(".legend")
.data(selectedCountries)
.join("text")
.attr("x", width - margin.right + 5)
.attr("y", (d, i) => margin.top + i * 20)
.attr("dy", "0.35em")
.attr("fill", d => color(d))
.text(d => d);
return svg.node();
}