Create a gist now

Instantly share code, notes, and snippets.

@mbostock /.block forked from mbostock/.block
Last active May 14, 2018

Embed
Histogram
redirect: https://beta.observablehq.com/@mbostock/d3-histogram
@hirokai

This comment has been minimized.

Show comment
Hide comment
@hirokai

hirokai 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?

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

This comment has been minimized.

Show comment
Hide comment
@wangxuq

wangxuq 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

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

This comment has been minimized.

Show comment
Hide comment
@aww

aww 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

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