Interactivity
D3plus charts are interactive out of the box: hovering a shape highlights it and shows a tooltip, and a legend lets viewers toggle series. Everything below works identically on the SVG and Canvas backends.
Tooltips
Section titled “Tooltips”Tooltips are on by default. Turn them off with tooltip: false, or customize
their contents and styling with tooltipConfig (a
Tooltip configuration):
<BarChart config={{ data, groupBy: "region", x: "quarter", y: "revenue", tooltipConfig: { title: d => d.region, tbody: [ ["Quarter", d => d.quarter], ["Revenue", d => `$${d.revenue}M`] ] }}} />Only at the deepest level
Section titled “Only at the deepest level”tooltip also takes a function, called as (d, i, {depth, maxDepth}) for each
hovered mark and legend entry, that returns whether to show its tooltip.
depth is the groupBy level the item stands for, counted from 0, and
maxDepth is the deepest level (groupBy.length - 1), so
depth === maxDepth leaves the levels above without tooltips. Here the regions
show none; click one to drill into its states, which do:
Active depth level for nested groupings.
On a chart that draws several levels at once (the rings of a Sunburst, the columns of an Icicle, the nodes of a Tree, the header strips of a nested Treemap), each mark reports its own level, so the same function keeps tooltips to the leaves.
The third argument also has legend, true when the hovered item is a legend
entry, so (d, i, {depth, maxDepth, legend}) => legend || depth === maxDepth
keeps the legend’s tooltips at every level.
Axis guides
Section titled “Axis guides”Hovering a mark on a Plot chart (LinePlot, BarChart, AreaPlot, a scatter or
bubble Plot, and the rest of the family) draws a dashed guide from its point to
each axis, with a badge on the axis showing the point’s value there in the
mark’s color. On a chart with a discrete axis, the shared tooltip’s crosshair is
that axis’s guide, and the value axis follows the hovered series (or the one
nearest the pointer); a bar is badged on its value axis only. Turn it off with
axisHover: false, keep one direction with "x" or "y", and style it with
axisHoverConfig:
<LinePlot config={{ data, groupBy: "region", x: "year", y: "revenue", axisHoverConfig: { guideConfig: {stroke: "#999", strokeDasharray: "2 2"}, badgeConfig: {fontSize: 11, padding: 3} }}} />See the axis guides example.
Axis tooltips
Section titled “Axis tooltips”An axis title or tick label that is shortened with an ellipsis shows its full
text in the chart’s tooltip when hovered or tapped. To say more about an axis,
give its config (xConfig, yConfig, x2Config or y2Config) a
titleTooltip or a tickTooltip:
titleTooltipis the text shown when hovering the axis title, or a function that receives the title and returns it.tickTooltipis the text shown when hovering any tick label, or a function that receives a tick’s value (the onetickFormatreceives) and its index, and returns the text for that tick’s label. The index counts the axis’s labels from the start of its domain: 0 is the lowest value on a value or time axis (the bottom label of a y axis, the left one of an x axis) and the first category on a categorical one, even whenreverseor a descendingdomaindraws the axis the other way round.
Either one also takes a Tooltip configuration,
applied on top of the chart’s tooltipConfig, whose accessors receive the
title (or the tick’s value and index) in place of a data point. false turns
the tooltip off, including the full text of a shortened label. A function
that returns false does the same for that one label, while one that returns
nothing leaves a shortened label its full text.
Hover the y-axis title, “Brazil” or “Vietnam”, and the shortened country names:
const notes = {
Brazil: "2023 estimate",
Vietnam: "Preliminary figure",
};
const config = {
data: [
{
country: "Democratic Republic of the Congo",
continent: "Africa",
gdp: 650,
},
{country: "Brazil", continent: "Americas", gdp: 10300},
{country: "Bosnia and Herzegovina", continent: "Europe", gdp: 8600},
{country: "Vietnam", continent: "Asia", gdp: 4300},
{
country: "Saint Vincent and the Grenadines",
continent: "Americas",
gdp: 10100,
},
],
groupBy: "continent",
x: "country",
y: "gdp",
xConfig: {
labelRotation: false,
maxSize: 40,
tickTooltip: d => notes[d],
},
yConfig: {
title: "GDP per capita",
titleTooltip: "Constant 2015 US$",
},
};
The same two options work on the other axes a chart draws from an axis config:
a Matrix’s rowConfig and columnConfig, the axisConfig of a Priestley or a
Gantt, a color scale’s axisConfig, a ParallelCoordinates’ axisConfig
(every axis) or dimensionConfig entry (one axis and its title), and a
Pyramid’s yConfig, whose tickTooltip its category labels take in the
center gutter as well as beside the chart. An Alluvial’s column titles take a
titleTooltip in its dimensionTitleConfig, and show their full text there
when shortened too. On a color scale drawn as swatches, titleTooltip applies
to its title and tickTooltip to each swatch’s label, which receives the value
and index of the label at that bucket’s start on a bucketAxis bar. A swatch
label showing its tooltip also highlights its bucket, as hovering the swatch
does, while the swatch itself still shows the bucket’s tooltip.
Hovering near a point
Section titled “Hovering near a point”Small points are hard to land on, so charts made of points act on the point
closest to the pointer. Over empty space, a gridline, or a link, the nearest
point whose edge is within hoverDistance pixels (20 by default) shows its
tooltip, hover highlight and axis guides, and a click there clicks it. The
tooltip points at the top of the point rather than following the pointer, and
holds still until a different point takes over. This
applies to scatter and bubble Plots (and Beeswarm), Network and ArcDiagram nodes, Geomap
points, and the dots on a Radar’s vertices; bars, areas, lines (which already follow the pointer’s nearest point),
and other area-filling marks keep exact hit-testing. A Plot with a discrete axis
and the shared tooltip snaps to the nearest column instead. Set
hoverDistance: 0 to react only to the point under the pointer, with a tooltip
that follows the pointer as on other marks:
<Plot config={{ data, groupBy: "id", x: "income", y: "life", hoverDistance: 30}} />See the nearest-point hover example.
Pointer events
Section titled “Pointer events”Register handlers through the on config key. Event names mirror
d3-selection and may carry a
namespace to scope the handler — .shape for data marks, .legend for legend
entries:
<BarChart config={{ data, groupBy: "region", x: "quarter", y: "revenue", on: { "click.shape": d => console.log("clicked", d), "mouseenter.shape": d => console.log("hover", d) }}} />Supported events include click, mouseenter, mouseleave, and mousemove.
A handler is called as (d, i, x, event): the hovered or clicked data row, its
index, the shape’s own datum (with the layout values d3plus added), and the
browser’s pointer event. this is the chart, so a handler can reconfigure and
redraw it. An error a handler throws shows in the console as an uncaught error,
and the chart’s other handlers for that event still run. An unscoped name
("click") fires for both shapes and legend entries. A shape type scopes a
handler to one kind of mark: "click.Rect" for a Treemap tile, "click.Bar"
and "click.Circle" for a Plot’s bars and points, "click.Path" for a Geomap
region, or "click.Box" for a BoxWhisker’s box, median, and whiskers.
A common use is opening a page for the clicked mark:
<Treemap config={{ data: [ {id: "Wikipedia", value: 60, url: "https://www.wikipedia.org"}, {id: "OpenStreetMap", value: 25, url: "https://www.openstreetmap.org"}, ], groupBy: "id", sum: "value", on: { "click.shape": d => window.open(d.url, "_blank", "noopener") }}} />See the Treemap click example.
Highlighting a series
Section titled “Highlighting a series”highlight applies a standing emphasis: pass a predicate and every matching
mark keeps its color while the rest fade to a neutral gray. Unlike hover or
active, it persists — it doesn’t clear when the pointer moves — so it’s ideal
for drawing attention to one series:
<BarChart config={{ data, groupBy: "region", x: "quarter", y: "revenue", highlight: d => d.region === "North" // North stays colored; others gray out}} />Pass false or null to clear the highlight. See the
BarChart highlight example.
Links in node-link charts
Section titled “Links in node-link charts”Network, Rings, Sankey, and ArcDiagram treat links as first-class marks.
Hovering a link highlights it and the two nodes it connects, and dims the rest;
its tooltip is titled “Source → Target” and lists the link’s own fields. Thin
links have a wider invisible hit area, so they are easy to point at, and
keyboard navigation reads each link as “Source to Target”. Hovering a node
lists its degree, betweenness, closeness, and cluster (see
Network measures; nodeTooltipStats
picks them) and, when the links differ in value, its strongest links
(nodeTooltipLinks sets how many, false for none).
A link whose source and target are the same node draws as a loop beside
the node in Network, Rings, and ArcDiagram, and behaves like any other link:
its tooltip reads “Node → Node”, and the node’s tooltip lists it as “↻ Node”.
A loop sits close to its node, so pointing at it always picks the loop rather
than the nearest node. Sankey can’t draw a flow back into the node it leaves,
so it leaves such links out and logs a warning.
Clicking a link (or pressing Enter on it with keyboard navigation) focuses it: the link and its two nodes stay bright and the rest dims, and Network zooms to fit them. Click it again, or click the chart’s empty background, to clear the focus. Rings and Sankey don’t zoom, so their focus stays in place; clicking a Rings node still re-centers the chart on it.
Every link accessor (linkSize, Sankey’s value, link shapeConfig
functions, arrows, and tooltip accessors) receives the link with source
and target set to the data of the nodes at its ends, so it can read their
fields directly:
<Network config={{ nodes, links, linkSize: d => d.weight, nodeTooltipLinks: 5, shapeConfig: { Path: {stroke: d => d.source.region === d.target.region ? "#495057" : "#adb5bd"} }}} />If you are upgrading, note that these accessors used to receive source and
target as the ids or indices from your links (or the chart’s internal
layout records). They now receive the node data, so read a node’s id with
d.source.id and its fields with d.source.<field>. Layout positions (x,
y, Sankey’s width, y0, y1) are no longer on the datum:
// Before: linkSize: d => lookup[d.source].weightlinkSize: d => d.source.weight,// Before: tooltipConfig: {title: d => `${d.source} to ${d.target}`}tooltipConfig: {title: d => `${d.source.id} to ${d.target.id}`}See the Network link tooltips example.
Geomap’s links work the same way: a link’s tooltip, spoken label, hit area,
and click focus (which zooms the map to the link) match the node-link charts,
and a coordinate point or shape at a link’s end lists its connections. Geomap
keeps its regions from dimming on hover, so hovering a link outlines it and
the marks at its ends instead; clicking it dims the rest of the map. Its links
are styled by linkColor rather than shapeConfig.Path, which styles the map’s
shapes. See the Geomap flow map example.
With linkBundle on, Network and Geomap links draw as bundled curves, and
every link interaction follows the curve: the hit area runs along it, a
tooltip appears wherever you point at it, and clicking it zooms to fit the
whole curve as well as its two ends. Hovering, zooming, and panning reuse
the bundling worked out for the layout, so they stay as quick as with
straight links. See the Network edge bundling example.
Legend
Section titled “Legend”A legend is shown automatically for grouped data. Clicking an entry toggles that
series; hovering highlights it. Each toggle goes on the chart’s Back history
with its drill-downs, so the Back button undoes legend clicks and drill-downs
in the order they happened; legendHistory: false keeps legend clicks off it.
Control the legend with legend and legendConfig:
<BarChart config={{ data, groupBy: "region", x: "quarter", y: "revenue", legend: true, // false to hide legendConfig: {title: "Region"}}} />Linked charts
Section titled “Linked charts”Give several charts the same link group and they move together: hovering,
active, highlight (including the search box), and legend hide/solo clicks in
one are mirrored in every other chart in the group. It’s plain config, so it
works the same from vanilla JS, React, or a serialized config object:
<Treemap config={{data, groupBy: ["region", "country"], sum: "revenue", link: "dashboard"}} /><BarChart config={{data, groupBy: "country", x: "country", y: "revenue", link: "dashboard"}} />Charts match rows by value, not by position. By default each chart uses its
own id (its current groupBy level). Use the object form to choose another key,
which can be named differently in each chart:
link: {group: "dashboard", by: "country_id"} // a data key or (d, i) => valueBecause matching goes by value, a coarse chart can drive a finer one. Hovering a
region tile lights up every bar whose row carries that region. A chart with no
row for the hovered value dims all of its marks. Legend toggles follow the same
rule: a legend entry is solo’d when any of its values is solo’d elsewhere, and
hidden once all of its values are hidden. Back in the chart you clicked undoes
the toggle in every chart in the group.
To stop mirroring one interaction, set it to false:
link: {group: "dashboard", hover: false} still shares legend toggles and
highlights. See the
linked charts example.
Timeline
Section titled “Timeline”Adding a time accessor enables a timeline beneath the chart. Viewers can scrub
or play through time periods, and the chart filters to the selected window:
<LinePlot config={{ data, // rows that include a "year" field groupBy: "series", x: "year", y: "value", time: "year", timelineConfig: {playButton: true}}} />Set timeline: false to keep the time filtering behavior without rendering the
timeline control.
A chart starts on its latest period; timeFilter (or timelineDefault)
starts it on another, and timelineConfig.on.end receives each period the
viewer picks. See
starting on a chosen period
and reading the selection.
timelineConfig.brushCursor sets the cursor over the timeline, and its
group’s d3plus-viz-timeline-ticks or d3plus-viz-timeline-buttons class
names how it is drawn (cursor and mode classes).
When points move between periods as the timeline plays, they leave motion
trails by default, and trailPersist can keep the whole path visible. See
Guides → Animation.
Zoom & pan
Section titled “Zoom & pan”Charts zoom and pan their content by default, with controls in the chart’s top-right corner (zoom in, zoom out, reset, and a drag-to-zoom brush that ends after one selection), wheel zoom, drag-to-pan, and double-click to zoom in.
Charts leave page scrolling alone: Ctrl/⌘ + wheel (or a trackpad pinch)
zooms, a plain wheel scrolls the page, and on touch screens one finger
scrolls while two fingers pinch-zoom — one finger pans only once the chart is
zoomed in. Every chart, Geomap and Network included, works this way by
default. Set zoomScroll to true (any wheel, such as for a full-page map),
"modifier", or false (no wheel zoom) to choose. A title,
subtitle, total, or top/right legend wraps or shifts to leave room for the
controls. Set zoom: false to turn it all off. Zoom starts off where it
doesn’t help read the chart (Bullet, Calendar, Funnel, Gantt, Gauge, and Waffle) and
on ParallelCoordinates, where it would slide the axes out from under their
brushes; set zoom: true to turn it on. Zoomed content is clipped to
the chart area, so the legend, title, and timeline stay put. While a drag
pans the chart (or turns a globe) or the wheel zooms it, the tooltip hides
and nothing stays hovered; the next move afterwards shows them again for
whatever is under the pointer.
Clicking a node in a Network or ArcDiagram focuses it and its neighbors and zooms to them; clicking it again, or the empty background, clears the focus.
On a Geomap globe (a projection that clips to a circle, such as
"geoOrthographic"), dragging turns the globe instead of panning it, keeping
the place under the pointer as it goes; the wheel, a pinch, and the zoom
buttons still zoom, and reset turns it back to projectionRotate. A drag
never counts as a click, so one that ends on a link or a point doesn’t
focus it. With the chart focused, Shift and the arrow keys turn the
globe 10° a press (see Keyboard Navigation),
and the zoom buttons and reset are reachable with Tab. See the Geomap globe example.
The control buttons are real <button>s: the brush toggle carries
aria-pressed and an .active class while on, and by default paints the OS
accent color. Set zoomControlClassName to style them with your own CSS.
The four control icons render as inline SVGs by default; zoomControlIcons
overrides any of them — pass a raw HTML string, or a mount function
((el) => void | (() => void)) that receives the button’s reserved icon
element to render into imperatively. That’s the escape hatch for a live
component: a brand icon from a React tree (createRoot(el).render(<Icon/>)),
a Vue app, anything. The function runs once per button element — an ordinary
redraw (pan, zoom, a data update) leaves a mounted icon alone; only something
that changes the buttons’ own markup (the brush toggling, a locale change, a
new zoomControlClassName) tears it down first, calling the cleanup function
your mount function returned, if any. The attribution credit’s “ⓘ” badge (see
attribution) takes the same treatment via attributionIcon.
Plot-based charts (BarChart, LinePlot, AreaPlot, StackedArea, BoxWhisker, BumpChart, Plot itself, and the other charts built on Plot) zoom their data instead of the picture: each linear or time axis stays in place and rescales its domain, re-ticking for the window it shows, while category and log axes stay fixed. A bar chart of categories zooms and pans along its value axis only; a scatter plot with two linear axes zooms in both directions. A brushed box fills the plot along the axes that zoom, so a LinePlot brushed across its width shows exactly the brushed y range, and a scatter plot shows the box’s range on its tighter axis with the box centered on the other.
How far you can zoom in adapts to what’s drawn:
by default, the limit is the scale at which the chart’s smallest shape fills
the chart area (a line or area series counts each segment between points), so
a few large shapes allow little zoom while a detailed map zooms all the way
into its smallest path. Set zoomMax to fix the limit instead. Tune the rest
with zoomFactor, zoomScroll, zoomPan, and zoomPadding — see the
Geomap examples for custom zoom,
disabling zoom, and zoom limits.
Zooming without the buttons
Section titled “Zooming without the buttons”zoomControls: false hides the four buttons and gives their corner back to
the title, legend, and other top content, which no longer leave room for
them; zoom itself stays on (zoom: false still turns everything off). Two
more options change what the pointer does:
zoomDrag: "brush"makes a mouse drag draw a box and zoom into it when you let go, as the brush button does but without switching brush mode on. A press that doesn’t move more than a few pixels is still a click, so it reaches the shape under it, and hovering still shows tooltips; once a drag begins, the tooltip hides until the next move after it. Hold Shift while dragging to pan instead (whenzoomPanallows), and press Escape mid-drag to cancel the box. The wheel, a pinch, and one-finger touch panning work as with the default"pan".zoomDoubleClicksets what a double-click (or a double-tap) does:"in"(the default) doubles the zoom around the pointer,"reset"returns to the chart’s initial view, andfalsedoes nothing.
Drag across this chart to zoom into part of it, and double-click to reset:
Whether the zoom-control buttons (zoom in, zoom out, reset, and brush) show in the chart's top-right corner. false hides them and gives the room they take back to the chart's title, legend, and other top content, while zooming stays on: the wheel, pinch, drag, and double-click gestures still work, and the chart's zoomIn, zoomOut, zoomReset, and zoomBrush methods let buttons of your own drive it. Defaults to true.
What a mouse drag on the chart does. "pan" (the default) pans it (see zoomPan). "brush" draws a box and zooms into it on release, as the brush button does, without turning brush mode on: a click that doesn't drag still reaches the shape under it, and hovering still shows tooltips. Shift + drag pans in "brush" mode, and touch keeps panning and pinching as in "pan".
What a double-click on the chart does: "in" (the default) doubles the zoom around the pointer (Shift + double-click halves it), "reset" returns to the chart's initial view, like the reset button, and false does nothing.
Every chart also has zoomIn(), zoomOut(), zoomReset(), and
zoomBrush(on) methods that do exactly what the buttons do, whether or not
they show, so buttons of your own (beside the rest of a page’s toolbar, say)
can drive the zoom. zoomIn and zoomOut step by zoomFactor about the
center of the chart area, and zoomBrush() with no argument reports whether
brush mode is on (it turns itself off once a box zooms). They do nothing
while zoom is off or before the chart first renders:
const chart = new d3plus.LinePlot() .select("#chart") .config({data, groupBy: "id", x: "x", y: "y", zoomControls: false}) .render();
document.querySelector("#zoom-in").onclick = () => chart.zoomIn();document.querySelector("#zoom-out").onclick = () => chart.zoomOut();document.querySelector("#reset").onclick = () => chart.zoomReset();document.querySelector("#brush").onclick = () => chart.zoomBrush(!chart.zoomBrush());