Skip to main content
100%

Reusable D3 Tooltip

✓ Published0🌍 Public
663anp3ca
Last edited Sep 23, 2018
Created on Sep 23, 2018

This example demonstrates a reusable tooltip function for D3 v4 bar charts, built with SVG. The tooltip, defined in tooltip.js, displays data attributes (name, description) in a styled black rounded rectangle with white text. It tracks mouse position to position itself within a defined extent, flipping sides dynamically based on cursor quadrant. The bar chart itself uses dummy data with categorical x-axis and linear y-axis, and the tooltip is attached to each bar via `.each(tooltip.events)`, preserving any other event listeners. The function is highly configurable through methods like `.tips()`, `.fontSize()`, `.padding()`, and `.margin()`, making it reusable across charts.

AI-generated description

This is my first attempt at a reusable function for creating tooltips on D3 charts.

Built with blockbuilder.org

forked from <a href='http://bl.ocks.org/TommyCoin80/'>TommyCoin80</a>'s block: <a href='http://bl.ocks.org/TommyCoin80/b2dbfadc95b2b1f58b8ff307c2414a49'>Reusable D3 Tooltip</a>

mit Licensed

Similar vizzes