Tutorials 9 min read

How to Visualize a Knowledge Graph

A graph you cannot see is a graph you cannot debug. But naive visualization fails at 5,000 nodes and produces useless hairballs at 50,000. This tutorial walks through layout algorithms, rendering libraries, and the aggregation tricks that let you visualize graphs at every scale.

Step 1: Pick a layout that matches the question

Layout is informational. Force-directed reveals clusters. Hierarchical reveals flow. Circular and matrix layouts handle dense graphs better than either.

Step 2: Pick a rendering library by node count

Cytoscape.js for 100-10K nodes. D3+SVG up to 2K. Sigma.js (WebGL) for 100K+. Gephi for offline. Pick by your actual node count.

Step 3: A working Cytoscape.js example

Below is the minimum viable Cytoscape.js setup with cose-bilkent layout, sane styling, and click-to-expand nodes. This is roughly what KnodeGraph's GraphCanvas does internally.

Step 4: Survive a graph that will not fit on screen

Past 5,000 nodes, the fix is aggregation, not better layout. Run Louvain or Leiden community detection and collapse each community to a super-node.

Step 5: Style for legibility, not prettiness

Use colour for node type (max 7 hues). Use size for centrality. Use edge thickness for weight. Resist using all four channels at once.

Common pitfalls

  • Drawing labels on every node. Past 200 visible labels it is pure noise.
  • Letting force-directed layouts run forever. Cap iterations at 1000-2000.
  • Random colour assignment per node type. Use perceptually uniform palettes (viridis, OkabeIto).
  • Showing all edges. Above 5K edges the graph is illegible.
  • Forgetting accessibility. Encoded-by-colour graphs fail for ~8% of male users.

Related reading

Frequently Asked Questions

Why does my graph look like a hairball?

Almost always because you are showing too many edges. Filter by relationship type or weight before rendering.

Should I use 3D for big graphs?

Almost never. Munzner 2014 shows 3D node-link diagrams are harder to read than 2D except for genuinely 3D data.

How do I export the visualization?

Cytoscape.js has built-in PNG/JPG export via `cy.png()`. For SVG, use the `cytoscape-svg` extension.

Can I render this server-side?

Yes — use `cytoscape-headless` with jsdom. Useful for embedding graph snapshots in PDF reports.

How do I make the graph interactive on mobile?

Cytoscape.js handles touch events natively. Add pinch-to-zoom and a tap-to-select pattern instead of hover.

Source

Fruchterman & Reingold (1991), 'Graph drawing by force-directed placement', Software: Practice & Experience 21(11), introduced the spring-electrical model that every modern force-directed layout descends from. Cytoscape.js implements it via the cose-bilkent extension and has been cited in 2,500+ papers since 2016. [link]

Ready to Try KnodeGraph?

Start free with 3 graphs and 100 nodes. Upgrade to Pro for AI extraction, unlimited graphs, and 50K nodes.

Get Started Free