Adapted from Mike Bostock's
Build Your Own Graph!
and
Histogram
examples.