Public
Edited
Sep 23
197 forks
Importers
19 stars
Global temperature trendsBeeswarm, Log ScaleContoursDensity contoursBubble chart componentCircle packing componentExploring Data with Vega-LiteStreaming data into VegaVega-Lite Line ChartBrushable scatterplotVega-Lite ScatterplotNight Skies — Lights and Light Pollution WebGL GlobePhysics based t-SNEGraphvizRidgeline plotZoomable sunburstHierarchical edge bundlingMethods of Comparison, ComparedChord diagramA Guide to Guides: Axes & Legends in VegaPSR B1919+21HexbinStacked-to-grouped barsTree of LifeHeat indexZoomable circle packingMarimekkoVizsla and Vega-LiteDirectly labelling linesParallel coordinatesCollapsible treeTangled tree visualizationMarey’s TrainsWorld History TimelineSmall multiple chart cartogramThe Real MVP in the NBAAnimated treemapDensity Contour Matrix with BrushingStars and constellationsHertzsprung–Russell diagramThe Coronavirus landscapeGitHub BurndownCandlestick ChartConcentration values vs. TimeA few days of CO2 levels in my homeIrregular bins histogramELD ViewerDistributions and summary statistics - a collection of Plot examplesMermaidBivariate Bubble MapD3 galleryCalendarStacked bar chartDot plotConnected scatterplotCandlestick chartHistogramForce-directed graphDisjoint force-directed graphIndex chartSankey diagramLine chart, percent changeStacked area chart
Bubble chart
Area chartHorizontal bar chartRadial tidy treeCircle packingIcicleStreamgraphTidy treeCluster treeSunburstHorizon chartBox plotScatterplotDifference chartBand chartBar chart transitionsTreemapLine chart, multiple seriesScatterplot matrixBrushable scatterplot matrixPlayfair's Wheat and Wages
Also listed in…
Gallery
d3-hierarchy
Insert cell
Insert cell
Insert cell
chart = {
// Specify the dimensions of the chart.
const width = 928;
const height = width;
const margin = 1; // to avoid clipping the root circle stroke
const name = d => d.id.split(".").pop(); // "Strings" of "flare.util.Strings"
const group = d => d.id.split(".")[1]; // "util" of "flare.util.Strings"
const names = d => name(d).split(/(?=[A-Z][a-z])|\s+/g); // ["Legend", "Item"] of "flare.vis.legend.LegendItems"

// Specify the number format for values.
const format = d3.format(",d");

// Create a categorical color scale.
const color = d3.scaleOrdinal(d3.schemeTableau10);

// Create the pack layout.
const pack = d3.pack()
.size([width - margin * 2, height - margin * 2])
.padding(3);

// Compute the hierarchy from the (flat) data; expose the values
// for each node; lastly apply the pack layout.
const root = pack(d3.hierarchy({children: data})
.sum(d => d.value));

// Create the SVG container.
const svg = d3.create("svg")
.attr("width", width)
.attr("height", height)
.attr("viewBox", [-margin, -margin, width, height])
.attr("style", "max-width: 100%; height: auto; font: 10px sans-serif;")
.attr("text-anchor", "middle");

// Place each (leaf) node according to the layout’s x and y values.
const node = svg.append("g")
.selectAll()
.data(root.leaves())
.join("g")
.attr("transform", d => `translate(${d.x},${d.y})`);

// Add a title.
node.append("title")
.text(d => `${d.data.id}\n${format(d.value)}`);

// Add a filled circle.
node.append("circle")
.attr("fill-opacity", 0.7)
.attr("fill", d => color(group(d.data)))
.attr("r", d => d.r);

// Add a label.
const text = node.append("text")
.attr("clip-path", d => `circle(${d.r})`);

// Add a tspan for each CamelCase-separated word.
text.selectAll()
.data(d => names(d.data))
.join("tspan")
.attr("x", 0)
.attr("y", (d, i, nodes) => `${i - nodes.length / 2 + 0.35}em`)
.text(d => d);

// Add a tspan for the node’s value.
text.append("tspan")
.attr("x", 0)
.attr("y", d => `${names(d.data).length / 2 + 0.35}em`)
.attr("fill-opacity", 0.7)
.text(d => format(d.value));

return Object.assign(svg.node(), {scales: {color}});
}
Insert cell
data = (await FileAttachment("flare.csv").csv({typed: true})).filter(({value}) => value !== null)
Insert cell
import {Swatches} from "@d3/color-legend"
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