chart4 = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
const players = svg
.append("g")
.selectAll("circle")
.data(sample_data_with_continent)
.join("circle")
.attr("cx", d => x(d.age) + Math.random() * 20)
.attr("cy", d => y(d.wage_eur))
.attr("r", d => r(d.overall))
.attr("stroke", d => continentColor(d.continent))
.attr("fill", d => continentColor(d.continent))
.attr("opacity", 0.75);
players.append("title").text(tooltip);
svg
.append("text")
.attr("transform", `translate(${width / 2}, ${margin.top - 10})`)
.attr("font-family", "Ariel, Helvetica, sans serif")
.attr("text-anchor", "middle")
.attr("font-size", 18)
.attr("fill", `hsl(0, 0%, 25%)`)
.text("Wages (Euros) by Player Age");
svg.append("g").call(xAxis);
svg.append("g").call(yAxis);
const size = 6;
svg
.append("g")
.selectAll("circle")
.data(uniqueOrderedContinents)
.join("circle")
.attr("cx", width - margin.right * 14)
.attr("cy", (d, i) => 100 + i * (size + 20))
.attr("r", size)
.attr("stroke", d => continentColor(d))
.attr("fill", d => continentColor(d))
.attr("opacity", 1.0);
svg
.append("g")
.selectAll("text")
.data(uniqueOrderedContinents)
.join("text")
.attr("x", width - margin.right * 14 + size * 1.5)
.attr("y", (d, i) => 100 + i * (size + 20))
.attr("fill", d => continentColor(d))
.attr("text-anchor", "left")
.attr("alignment-baseline", "middle")
.attr("font-family", "Ariel, Helvetica, sans serif")
.attr("font-size", "14px")
.text(d => d);
return svg.node();
}