function graph(data) {
const marks = [
Plot.ruleY([0]),
];
const colorScale = d3.scaleOrdinal(d3.schemeCategory10)
.domain(variablesY);
variablesY.forEach((variableY, index) => {
const color = coloresY[index % coloresY.length];
marks.push(
Plot.lineY(data, { x: variableX, y: variableY, stroke: color, tip: true })
);
});
const container = document.createElement("div");
container.appendChild(selectDiv());
const legend = d3.select(document.createElement("div"))
.style("margin-bottom", "10px")
.style("text-align", "center");
variablesY.forEach((variableY, index) => {
const color = colorScale(variableY);
const legendItem = legend.append("div")
.style("display", "inline-block")
.style("margin-right", "10px");
legendItem.append("div")
.style("width", "10px")
.style("height", "10px")
.style("background-color", color)
.style("margin-right", "5px");
legendItem.append("span")
.text(variableY);
});
container.appendChild(legend.node());
container.appendChild(Plot.plot({
width: 1200,
height: 500,
x: {
label: ejeX,
tickFormat: d3.format(".0f")
},
y: {
label: ejeY,
grid: true,
tickFormat: d => d3.format(",.0f")(d).replace(/,/g, ".") + '%'
},
marks: marks
}));
return container;
}