Public
Edited
Mar 20
6 stars
Insert cell
Insert cell
Plot.barY([1, 2, 3, 2, 4, 1, 7, 3, 1, 2], {href, fill: "steelblue"}).plot({height: 200})
Insert cell
mutable value = null
Insert cell
Plot.barX(
d3.group(penguins, (d) => d.species),
{ x: (d) => d[1].length, y: "0", fill: "0", href }
).plot({ marginLeft: 80, y: { label: "species" } })
Insert cell
// When clicking on an element in the chart, dispatch a custom event on the window.
// The name ("clicked") is arbitrary. Information payload in the detail property.
href = (value, index) =>
`javascript:dispatchEvent(
new CustomEvent("clicked", {
detail: ${JSON.stringify({ value, index })}
})
);`
Insert cell
// Add the matching event listener on the window
{
function callback(event) {
// do what you want with the value; here we update a Mutable to allow us to inspect the data
mutable value = event.detail;
}
addEventListener("clicked", callback);
invalidation.then(() => removeEventListener("clicked", callback));

return html`<small><em>ready…`;
}
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more