Troubleshooting

visx Troubleshooting: Fixes for Common Chart Problems

Most visx problems come from a small set of causes. Work through this list in order. Each entry gives the symptom, why it happens, and the fix.

1. The chart is blank or cut off

Likely cause: the container has no height. In visx 4, ParentSize renders an outer div with height: 100% and draws your chart inside an absolutely positioned, overflow: hidden box. If the parent has no height, everything inside is clipped to zero.

Fix: give the element around ParentSize a real height:

<div style={{ height: 320 }}>
  <ParentSize>{({ width }) => <Chart width={width} height={320} />}</ParentSize>
</div>

We ran into this while building our own starter kit. Upgrading from v3, where the old wrapper behaved differently, is the most common way to trigger it.

2. Width is 0 or the chart never grows

Likely cause: a flex or grid child with a default min-width: auto, or a parent that's hidden (display: none) when it first renders.

Fix: add min-width: 0 to the flex or grid item that holds the chart. For tabs and modals, render the chart only once its panel is visible, or call the resize function ParentSize passes to its children.

3. Bars grow downward or the chart is upside down

Cause: SVG's y-axis points down. Fix: set your linear scale's range to [innerHeight, 0], and draw bars from y = innerHeight - barHeight.

4. "Module not found" or "Cannot find module '@visx/…'"

  • Missing package: visx is split into many packages. Importing @visx/grid requires installing @visx/grid.
  • Deep import: paths like @visx/shape/lib/shapes/Bar were removed in v4. Import from the root: @visx/shape.
  • Missing transitive dependency: v4 no longer pulls in lodash or prop-types. If your own code imports them, add them to your package.json.

5. Strange TypeScript errors after upgrading

Cause: mixed visx versions, for example @visx/shape@4 next to @visx/scale@3. Fix: run npm ls | grep @visx, upgrade every package to the same major, then delete node_modules and your lockfile if duplicates remain. Also make sure @types/react matches your React version, since it's now an optional peer dependency.

6. "parentRef.current is undefined" with useParentSize

Cause: in visx 4, useParentSize returns a callback ref. Fix: attach parentRef to your element as before, but read the DOM node from the returned node value instead of parentRef.current.

7. The tooltip appears in the wrong place

  • Use localPoint(event) from @visx/event to get coordinates relative to the SVG, not the page.
  • The element containing both the SVG and the tooltip needs position: relative.
  • If a parent has overflow: hidden or a transform, use useTooltipInPortal so the tooltip renders in a portal.

8. Hydration warnings in Next.js

Cause: the server rendered a different width than the browser. Fix: mark hook-based chart components with 'use client', pass an initialSize to ParentSize, or only render the chart after mount. Reserve the height with CSS so the page doesn't jump.

9. XYChart axis doesn't show

In visx 4, @visx/xychart's axis renders nothing until a series with non-empty data is registered. If you need an axis while data loads, render a placeholder Axis from @visx/axis.

10. The chart is slow with lots of data

SVG creates one DOM node per mark. Thousands of points can get sluggish. Aggregate or sample the data, memoise scales with useMemo, and avoid re-creating data arrays on every render. For very large datasets, a Canvas-based renderer is the better tool.

Still stuck?

Compare your code with the matching component in our starter kit, which builds cleanly against visx 4.0.0. Search the official visx issue tracker, or send us a question with a short code sample.