Public
Edited
Dec 26, 2023
1 star
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.dot(penguins, {x: "body_mass_g", y: "flipper_length_mm", fill: "species", r: 4, render: addClick})
]
})
Insert cell
addClick = (index, scales, values, dimensions, context, next) => {
const el = next(index, scales, values, dimensions, context);
const circles = el.querySelectorAll("circle");
for (let i = 0; i < circles.length; i++) {
const d = {index: index[i], x: values.channels.x.value[i], y: values.channels.y.value[i]};
circles[i].addEventListener("click", () => mutable clicked = d);
}
return el;
}
Insert cell
mutable clicked = null
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