chart = {
const svg = d3.create("svg").attr("viewBox", [0, 0, width, height]);
svg.append("g").call(x_axis);
svg.append("g").call(y_axis);
svg
.append("text")
.attr("text-anchor", "middle")
.attr("x", width / 2)
.attr("y", height - 10)
.text("Arm Span in CM");
svg
.append("text")
.attr("text-anchor", "end")
.attr("x", -height / 2.5)
.attr("y", 15)
.attr("transform", "rotate(-90)")
.text("Height in CM");
svg
.append("text")
.attr("text-anchor", "middle")
.attr("x", width / 2)
.attr("y", margin.top - 5)
.text("Arm Span vs Height in Genders");
const circles = svg.selectAll('circle').data(chart_data);
circles
.join(
enter =>
enter
.append("circle")
.attr("cx", d => x_scale(d['x']))
.attr("cy", d => y_scale(d['y'])),
update => update,
exit =>
exit
.transition()
.duration(500)
.attr("r", 0)
.remove()
)
.attr('cx', d => x_scale(0))
.attr('cy', d => y_scale(0))
.attr('r', 10)
.style('fill', d => {
if (d["color"] === "Female") {
return "red";
} else {
return "blue";
}
})
.style('opacity', 0.6)
.transition()
.duration(500)
.attr('cx', d => x_scale(d['x']))
.attr('cy', d => y_scale(d['y']));
return svg.node();
}