Published
Edited
Sep 14, 2022
Insert cell
Insert cell
chart = {
const chart = new G2.Chart({
width,
height: 800
});
const names = new Set(population.map((d) => d.name));
const colors = d3.quantize(
(t) => d3.interpolateSpectral(t * 0.8 + 0.1),
names.size
);

chart.coordinate({ type: "theta" });

chart
.interval()
.data(population)
.scale("color", { range: colors, guide: null })
.encode("y", "value")
.encode("color", "name")
.encode("label", "name")
.encode("tooltip", "value")
.style("label", { position: "inside" })
.style("stroke", "white");

return node(chart.render());
}
Insert cell
Insert cell
Insert cell
Improvements:

- [ ] Add `QuantizeSequential` Scale.
- [ ] `inside` position support `radius` position.
- [ ] Support `inset` options for interval.
- [ ] `Path` animation
Insert cell
{
const options = {
type: "interval",
coordinates: [{ type: "theta" }],
scale: {
color: {
guide: null,
interpolator: (t) => d3.interpolateSpectral(t * 0.8 + 0.1)
}
},
encode: {
y: "value",
color: "name",
label: "name"
},
style: {
inset: 0.1
},
children: [
{
type: "text",
encode: { text: "name" },
transform: [{ type: "hideOverlap" }],
style: { position: "inside", radius: 0.8 }
},
{
text: "text",
encode: { text: "value" },
transform: [{ type: "hideOverlap" }],
style: { position: "inside", radius: 0.8, dy: "1em" }
}
]
};
return md`A better spec...`;
}
Insert cell
Insert cell
PieChart(population, {
name: (d) => d.name,
value: (d) => d.value,
width,
height: 500
})
Insert cell
Insert cell
Insert cell
Insert cell
Insert cell
import { PieChart } from "@d3/pie-chart"
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