Skip to main content
100%

D3.js v4 Force Directed Graph with Labels

✓ Published0🌍 Public
GGerardoFurtado
Last edited Apr 18, 2019
Created on Apr 18, 2019

This example shows a force-directed graph of character co-occurrence in *Les Misérables*, with each character’s name displayed beside its node. It adapts Mike Bostock’s original diagram by wrapping each circle and its text label in a `<g>` element, enabling labels to move with nodes during interaction. The visualization uses D3.js v4’s `d3.forceSimulation`, `d3.forceLink`, `d3.forceManyBody`, and `d3.forceCenter` to compute layout, and renders with SVG. Nodes are color-coded by group using `d3.scaleOrdinal` and `d3.schemeCategory20`, with data loaded from a `miserables.json` file.

AI-generated description

A quick adaptation of Mike Bostock's force-directed graph showing character co-occurence in Les Misérables. In this version, the character names are displayed. This is accomplished by wrapping both circles and text svg components within a group svg component.

Compare to the original diagram by Mike Bostock.

forked from <a href='http://bl.ocks.org/heybignick/'>heybignick</a>'s block: <a href='http://bl.ocks.org/heybignick/3faf257bbbbc7743bb72310d03b86ee8'>D3.js v4 Force Directed Graph with Labels</a>

forked from <a href='http://bl.ocks.org/GerardoFurtado/'>GerardoFurtado</a>'s block: <a href='http://bl.ocks.org/GerardoFurtado/91368069a381009d30468aa9774c0de3'>D3.js v4 Force Directed Graph with Labels</a>

gpl-3.0 Licensed

Similar vizzes