Public
Edited
Apr 22
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
{
// 1. Creación de un área de dibujo (350x350 pixeles).
// Si lo consideran necesario, pueden modificar el tamaño del canvas.
// También es posible que necesiten más de una celda para resolverlo.
const svg = d3.create("svg")
.attr("width",width)
.attr("height",height);
// Ejes
svg.append("g")
.attr("transform", `translate(0, ${height - margin.bottom})`)
.call(d3.axisBottom(x));

svg.append("g")
.attr("transform", `translate(${margin.left}, 0)`)
.call(d3.axisLeft(y));

// Etiquetas de los ejes
svg.append("text")
.attr("x", width / 2)
.attr("y", height - 5)
.attr("font-size", "8px")
.attr("text-anchor", "middle")
.text(ejeX);

svg.append("text")
.attr("transform", "rotate(-90)")
.attr("x", -height / 2)
.attr("y", 15)
.attr("font-size", "8px")
.attr("text-anchor", "middle")
.text(ejeY);

// Puntos
svg.selectAll("circle")
.data(datosFiltrados)
.join("circle")
.attr("cx", d => x(d[ejeX]))
.attr("cy", d => y(d[ejeY]))
.attr("r", 4)
.attr("fill", "steelblue")
.attr("opacity", 0.7)

// Título
svg.append("text")
.attr("x", width / 2)
.attr("y", margin.top - 20)
.attr("text-anchor", "middle")
.attr("font-size", "10px")
.text(`Gráfico de dispersión: ${ejeX} vs. ${ejeY}`);
return svg.node();
}
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell

Purpose-built for displays of data

Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Learn more