{
const width = 800;
const height = 400;
const margin = { top: 30, right: 10, bottom: 10, left: 20 };
const columns = ["Age", "Fare", "SibSp", "Survived"];
const data = processedData.map(d => ({
Age: d.Age,
Fare: d.Fare,
SibSp: d.SibSp,
Survived: d.Survived,
Sex: d.Sex
}));
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height);
const x = d3.scalePoint()
.domain(columns)
.range([margin.left, width - margin.right]);
const y = {};
columns.forEach(col => {
y[col] = d3.scaleLinear()
.domain(d3.extent(data, d => d[col]))
.range([height - margin.bottom, margin.top]);
});
const line = d3.line()
.defined(([, value]) => !isNaN(value))
.x(([col]) => x(col))
.y(([col, value]) => y[col](value));
svg.append("g")
.selectAll("path")
.data(data)
.join("path")
.attr("d", d => line(columns.map(col => [col, d[col]])))
.attr("fill", "none")
.attr("stroke", d => d.Sex === "male" ? "blue" : "orange")
.attr("stroke-opacity", 0.5 );
svg.append("g")
.selectAll("g")
.data(columns)
.join("g")
.attr("transform", d => `translate(${x(d)},0)`)
.each(function(d) { d3.select(this).call(d3.axisLeft(y[d])); })
.append("text")
.attr("y", margin.top - 10)
.attr("text-anchor", "middle")
.text(d => d)
.style("fill", "black");
return svg.node();
}