Sphere
Log in Join
☆ 3

d3 line chart with 100k points freezes the browser

D3 v7, React frontend, trying to render a line chart with about 100,000 points from a time-series API. The browser freezes for several seconds on initial render and hover tooltips are unusable. SVG path with that many points is huge. I've thought about downsampling but the whole point is to let users zoom in and see detail. Is there a way to render incrementally, or should I switch to canvas/WebGL for the main line and use SVG only for axes? What do people do for large time series in D3?

⚑ Report

4 replies

☆ 0
Y yaml ·2026-11-11#1

100k points in SVG is too many - each point in a path is still one giant string the browser has to parse and rasterize. Canvas is the standard fix for the dense line: keep SVG for axes and brush, draw the line on a canvas layered on top. D3 scales still work with canvas context. For hover, use d3.quadtree for nearest-point lookup instead of DOM events. Or downsample for the overview and only draw full resolution in the zoomed window.

⚑ Report
☆ 0
C cron48 ·2026-11-14#2

Canvas for the line + SVG axes sounds doable. How do I handle the zoom - do I redraw the canvas on every zoom event? That might still be janky. Also I need tooltips; quadtree nearest-point lookup sounds good but does it work in screen coordinates after zoom?

⚑ Report
☆ 0
R rust21 ·2026-11-16#3

Redraw on zoom is fine if you throttle with requestAnimationFrame - don't do it on every wheel event. For the quadtree, build it in data space once and query with the inverted mouse position (xScale.invert(mouseX)) so it accounts for zoom automatically. Also only draw points in the visible x-domain - with zoom you can filter to the current extent, so even 100k points become a few thousand at high zoom.

⚑ Report
☆ 0
G ghost ·2026-11-16#4

Went canvas + SVG axes, quadtree for hover, and a requestAnimationFrame-throttled redraw that only draws points in the visible domain. Initial render is now instant and hover is responsive. For really large data (millions), look at WebGL (regl, deck.gl) or downsample with LTTB before drawing - but 100k is manageable with canvas. Key insight: SVG is for a few thousand elements max; anything denser goes on canvas.

⚑ Report
Log in to reply.