chart = {
const svg = d3
.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("overflow", "visible");
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
svg
.append("g")
.attr("class", "grid")
.attr("transform", `translate(${margin.left},0)`)
.call(
d3
.axisLeft(y)
.tickSize(-width + margin.right + margin.left)
.tickFormat("")
);
var props = [
'retailRecreation',
'groceryPharmacy',
'parks',
'transitStations',
'workplaces',
'residential'
];
var labels = [
'Retail & recreation',
'Grocery & pharmacy',
'Parks',
'Transit stations',
'Workplaces',
'Residential'
];
const path = svg
.append("g")
.selectAll("path")
.data(props)
.join("path")
.attr("fill", "none")
.attr("stroke", (d, i) => color(i))
.attr("stroke-width", 1.5)
.attr("d", d => line(d)(data));
const legendRects = svg
.append("g")
.selectAll("rect")
.data(props)
.join("g")
.attr(
"transform",
(d, i) =>
`translate(${width - margin.right + 20}, ${i * 20 + margin.top})`
);
legendRects
.append('rect')
.attr("width", 15)
.attr("height", 15)
.attr("fill", (d, i) => color(i));
legendRects
.append('text')
.attr('x', 17)
.attr('y', 10)
.attr('font-size', '12')
.text((d, i) => labels[i]);
return svg.node();
}