Skip to main content
Public

Share visualization

Loading preview…

d3 and canvas - the bind, the draw and the pick

vizhub.com

Shared links may look like this on X, LinkedIn, Slack, and Discord.

Before sharing, review the publishing checklist.

Choose how to deliver this visualization

LinkedIn caption

LinkedIn may not keep text supplied by the share sheet. Copy the caption and paste it into the post if needed. You can tag the VizHub company page when posting.

More options

Embed on a websiteCopy iframe embed code
Download & exportPNG, HTML, source ZIP

d3 and canvas - the bind, the draw and the pick

0
AAngelos Chatzimparmpas
Last edited May 23, 2022
Created on May 22, 2022

This example demonstrates a dynamic grid of colored cells on an HTML canvas, where each cell represents a data point. A hidden secondary canvas is used for mouse picking; each cell gets a unique color assigned via `genColor()`, and this color is mapped to the original data in a dictionary (`colourToNode`). When the user hovers over the visible canvas, the tooltip displays the corresponding data value by reading the pixel color from the hidden canvas. The visualization uses d3.v4 for data binding and transitions, and it redraws both canvases continuously.

AI-generated description

A bare minimum HTML page demonstrating use of CSS and JavaScript.

See also React Starter.

Comments

Sign in to join the discussion.

MIT Licensed