Public
Edited
Nov 22, 2023
Insert cell
Insert cell
Insert cell
data2 = FileAttachment("uefa_champions_winners.csv").csv()
Insert cell
T_cantidad = d3.rollup(data2, v => d3.count(v, d => + 1), d => (d['Score']) )
Insert cell
cantidad = [...T_cantidad].map(function (item) {
return { Resultado: item[0], cantidad: item[1] }
});
Insert cell
datosFiltrados = cantidad.filter(dato => dato.cantidad > 1);

Insert cell
Insert cell
Plot.plot({
marks: [
Plot.barX(datosFiltrados, {x: "cantidad", y: "Resultado", fill: "#ff8c38", sort: {y: "x", reverse: true, limit: 100}})
]
})
Insert cell
Insert cell
Insert cell
Asistencia = data2.map(entry => ({
Temporada: entry.Season,
Asistencia: parseInt(entry.Attendance, 10), // Asegúrate de que la asistencia sea tratada como un número
}));
Insert cell
// Mapear las temporadas a números
Asistencia2 = Asistencia.map((d, i) => ({ NumeroTemporada: i + 1, Asistencia: d.Asistencia }));
Insert cell
chart = {
const width = 1000;
const height = 800;
const margin = ({top: 20, right: 0, bottom: 30, left: 40});
const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height]);

const x = d3.scaleBand()
.domain(Asistencia2.map(d => d.NumeroTemporada))
.range([margin.left, width - margin.right])
.padding(0.1);

const y = d3.scaleLinear()
.domain([0, d3.max(Asistencia2, d => d.Asistencia)])
.nice()
.range([height - margin.bottom, margin.top]);

const line = d3.line()
.x(d => x(d.NumeroTemporada) + x.bandwidth() / 2)
.y(d => y(d.Asistencia));

svg.append("path")
.datum(Asistencia2)
.attr("fill", "none")
.attr("stroke", "steelblue")
.attr("stroke-width", 1.5)
.attr("d", line);

svg.append("g")
.attr("transform", `translate(0,${height - margin.bottom})`)
.call(d3.axisBottom(x).tickFormat(d3.format("d"))); // Formato para mostrar números enteros en el eje x

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

return svg.node();
}
Insert cell
Insert cell
Cantidad_e = d3.rollup(data2, v => d3.count(v, d => + 1), d => (d['Winners']) )
Insert cell
equipos = [...Cantidad_e].map(function (item) {
return { Nombre: item[0], cantidad: item[1] }
});
Insert cell
Insert cell
charts = {
const width = 1000;
const height = 800;
const margin = ({ top: 20, right: 20, bottom: 30, left: 40 });

const colorScale = d3.scaleOrdinal(d3.schemeCategory10.reverse());

const root = d3.hierarchy({ children: equipos })
.sum(d => d.cantidad);

const treemap = d3.treemap()
.size([width, height])
.padding(1)
.round(true);

treemap(root);

const svg = d3.create("svg")
.attr("viewBox", [0, 0, width, height])
.style("font", "10px sans-serif");

const cell = svg.selectAll("g")
.data(root.leaves())
.join("g")
.attr("transform", d => `translate(${d.x0},${d.y0})`);

cell.append("rect")
.attr("width", d => d.x1 - d.x0)
.attr("height", d => d.y1 - d.y0)
.attr("fill", d => colorScale(d.data.Nombre));

cell.append("text")
.attr("x", 3)
.attr("y", 12)
.text(d => d.data.Nombre);

return svg.node();
}
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