{
const chartWidth = 700;
const chartHeight = 450;
const paddingTop = 30;
const paddingRight = 25;
const paddingBottom = 40;
const paddingLeft = 50;
const xScale = d3.scaleLinear()
.domain(d3.extent(titanicDataSet, d => d.Age))
.nice()
.range([paddingLeft, chartWidth - paddingRight]);
const yScale = d3.scaleLinear()
.domain(d3.extent(titanicDataSet, d => d.Fare))
.nice()
.range([chartHeight - paddingBottom, paddingTop]);
const svgContainer = d3.create("svg")
.attr("width", chartWidth)
.attr("height", chartHeight)
.attr("viewBox", `0 0 ${chartWidth} ${chartHeight}`)
.style("max-width", "100%")
.style("height", "auto");
svgContainer.append("g")
.attr("transform", `translate(0,${chartHeight - paddingBottom})`)
.call(d3.axisBottom(xScale));
svgContainer.append("g")
.attr("transform", `translate(${paddingLeft},0)`)
.call(d3.axisLeft(yScale));
svgContainer.append("text")
.attr("x", chartWidth / 2)
.attr("y", chartHeight - paddingBottom + 30)
.attr("text-anchor", "middle")
.attr("font-size", "14px")
.attr("fill", "#000")
.text("Age of Passenger");
svgContainer.append("text")
.attr("x", -chartHeight / 2)
.attr("y", paddingLeft - 35)
.attr("transform", "rotate(-90)")
.attr("text-anchor", "middle")
.attr("font-size", "14px")
.attr("fill", "#000")
.text("Fare of the Ticket");
svgContainer.append("g")
.selectAll("circle")
.data(titanicDataSet)
.join("circle")
.filter(d => d.Age && d.Fare)
.attr("cx", d => xScale(d.Age))
.attr("cy", d => yScale(d.Fare))
.attr("r", 4)
.style("fill", d => d.Survived ? "#2ca02c" : "#d62728")
.style("opacity", 0.7);
return svgContainer.node();
}