Skip to main content
100%

Wrapping Long Labels

✓ Published0🌍 Public
Mmbostock
Last edited Feb 9, 2016
Created on Nov 20, 2013

This example demonstrates how to automatically wrap long axis labels onto multiple lines using D3.js (v3) in an SVG render. It visualizes satirical survey data from The Onion explaining why people are leaving Facebook, with each humorous reason plotted as a steel-blue bar. The custom `wrap` function splits label text into words, measures each line’s width via SVG’s `getComputedTextLength()`, and appends `tspan` elements to create multi-line tick labels sized to fit the bar’s range band. The chart uses `d3.scale.ordinal` for the x-axis and `d3.svg.axis` for labeling, with data loaded via `d3.tsv`.

AI-generated description

This example, using satirical data from The Onion, demonstrates how to wrap long axis labels to fit on multiple lines.

gpl-3.0 Licensed

Similar vizzes