Skip to content

Instantly share code, notes, and snippets.

@zischwartz
zischwartz / README.md
Created January 4, 2018 19:16 — forked from mbostock/README.md
Local Variables

It’s often desirable when using D3 to define local behavior, that is, behavior that is specific to an individual element, rather than the same for all elements in a selection. The simplest example of this is passing a function to selection.attr to compute an attribute value for each element.

But what happens if your local behavior is more complicated? What if you want multiple operations (multiple attributes, or elements) to have local behavior, but still share local state between them? For instance, when rendering small multiples of time-series data, you might want the same x-scale for all charts but distinct y-scales to compare the relative (not absolute) performance of each metric.

There are several ways to do this in D3:

  1. Make the y-scale global, but set the domain on the y-scale before use. (Example.)

  2. Use selection.each to create a local con

@zischwartz
zischwartz / Readme.md
Last active March 17, 2020 08:00 — forked from josiahdavis/Readme.md
Responsive Multi-Line Chart (D3 V5)

Responsive Multi-Line Chart