Skip to main content
100%

Wrapping Long Labels 2.0

✓ Published0🌍 Public
FFrissAnalytics
Last edited Sep 30, 2018
Created on Dec 8, 2016

This example demonstrates how to wrap long axis labels onto multiple lines in a horizontal bar chart, using satirical survey data from The Onion about why people are leaving Facebook. The chart displays six humorous reasons as categories on the x-axis, with corresponding percentage values plotted on the y-axis. The code uses the d3.svg.axis API to generate the axes, and a custom wrap function that leverages the getComputedTextLength() method on SVG text elements to measure and split label text into multiple tspans. The data itself is loaded from a TSV file using the d3.tsv method, and all rendering is done as SVG elements.

AI-generated description

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

forked from <a href='http://bl.ocks.org/mbostock/'>mbostock</a>'s block: <a href='http://bl.ocks.org/mbostock/7555321'>Wrapping Long Labels 2.0</a>

forked from <a href='http://bl.ocks.org/anonymous/'>anonymous</a>'s block: <a href='http://bl.ocks.org/anonymous/b237b631ac184c9f9fa4'>Wrapping Long Labels 2.0</a>

forked from <a href='http://bl.ocks.org/ericsoco/'>ericsoco</a>'s block: <a href='http://bl.ocks.org/ericsoco/647db6ebadd4f4756cae'>Wrapping Long Labels 2.0</a>

mit Licensed

Similar vizzes