Public
Edited
May 6, 2023
3 forks
6 stars
Insert cell
Insert cell
chart = {
const arc = vl
.markArc({ innerRadius: width / 13, padAngle: 0.01 })
.encode(
vl.order().count().sort("descending"), // Sort the layers
vl.theta().count().stack(true), // required for placing the labels
vl.color().fieldN(splitBy).scale({ scheme: "pastel1" })
);

const textConfig = { radius: width / 10, align: "center", dy: 7 };
const textName = arc
.markText(textConfig)
.encode(
vl.text().count(),
vl.detail().fieldN(splitBy), // Without this we will get only the totals
vl.color().value("Black")
);
const textValue = textName
.markText({ ...textConfig, dy: -7, fontWeight: "bold", fontSize: 14 })
.encode(vl.text().fieldN(splitBy));

return vl
.layer(arc, textName, textValue)
.width(width/2)
.data(data)
.render();
}
Insert cell
splitBy = "Species"
Insert cell
data = (await require("vega-datasets@2"))["penguins.json"]()
Insert cell
import{vl} from "@vega/vega-lite-api"
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