Skip to content

Instantly share code, notes, and snippets.

@mbostock
Forked from mbostock/.block
Last active May 14, 2018 11:02
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 16 You must be signed in to fork a gist
  • Save mbostock/3048450 to your computer and use it in GitHub Desktop.
Save mbostock/3048450 to your computer and use it in GitHub Desktop.
Histogram
redirect: https://beta.observablehq.com/@mbostock/d3-histogram
@hirokai
Copy link

hirokai commented Jan 9, 2015

In line 70:

    .attr("width", x(data[0].dx) - 1)

The code above gives negative width for some data I made.

Should x(data[0].dx) - 1 be x(data[0].dx) - x(0) actually?

@wangxuq
Copy link

wangxuq commented Aug 20, 2015

when I use these code to build the chart,the d3.scale.liner().domain([0,1]) cannot work, this is to say the line range cannot appear.why?
as bellow:
image

@aww
Copy link

aww commented Oct 10, 2015

@hirokai made a very good point about the width computation. This version obviously works, but it doesn't generalize to cases where the x-domain doesn't start at 0. It caused me to waste a little time when I first tried to apply this example to my situation. Width should be instead x(data[0].dx) - x(0) - 1 (assuming we still want gaps between the bins).
https://gist.github.com/aww/bf245ae8d58afcebd930

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment