How to create a histogram using d3.js and crossfilter data?

Here's my demo (permalink, it may take a second to download).

I have several problems with this:

  • The cross filter key does not reflect the upper bound. Therefore, the x axis is missing one step.

    enter image description here

    I managed to fix this by getting one group step size ( group.all()[1] - group.all()[0]) and then adding it to d3.extent(group.all())[1]. Since this is a dirty fix, I did not include it in the demo version (maybe a data gap). What is a less dirty way to get the group step size / fix the x axis?

  • There are uneven gaps between the bars. I cannot figure out how to fix x.scale mismatch with different datasets.

    enter image description here

    , . , ( ) :

    bar_width = math.round(graph_width/data_length);
    graph_width = bar_width*data_length;
    

    x.scale , . ; - . ?

    x.scale , bar_width graph_width x.scale . , , x.scale , .

+5
1

, . , , . , , , .

enter image description here

github.

+2

All Articles