Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>There is no <code>14</code> and there are two <code>8</code>s on the x-axis. This is because the <code>bins</code> function will diligently divide the range <code>= 14 - 1 = 13</code> into <code>14</code> intervals <a href="https://github.com/mbostock/d3/wiki/Histogram-Layout#wiki-bins" rel="nofollow">as per the API reference</a>:</p> <blockquote> <p>The bins may be specified as a number, in which case the range of values will be split uniformly into the given number of bins. Or, bins may be an array of threshold values, defining the bins; the specified array must contain the rightmost (upper) value, thus specifying n + 1 values for n bins. ...</p> </blockquote> <p>Before solving this issue, I am guessing that the second problem you are facing is that if the <code>rangeDefault</code> has negative values, then some values are not plotted. To fix that problem, being unaware of the exact need of it, I will start by removing the following:</p> <pre class="lang-js prettyprint-override"><code>rangeDefault[0] = 0; //All histograms start from 0 &lt;-- REMOVED </code></pre> <p>Then to fix the first problem, use the second form of arguments for <code>bins</code><a href="http://jsfiddle.net/xjMNr/" rel="nofollow">as shown here</a>:</p> <pre class="lang-js prettyprint-override"><code> var bins = []; for(var ii = settings.range[0], jj = 0; ii &lt;= settings.range[1] + 1; ii++, jj++) bins[jj] = ii; var data = d3.layout.histogram() .bins(bins)(settings.data); </code></pre> <p>I hope this addresses the primary queries.</p> <hr> <p>Adding the light grey indicator lines is fairly easy, <a href="http://jsfiddle.net/EXfCu/1/" rel="nofollow">as shown here</a>. The changes were:</p> <h1>vis.css</h1> <pre><code>.y.axis line.tick { opacity: .3; } </code></pre> <h1>vis.js</h1> <p>Moving the axis before the chart in the DOM because of how SVG is laid out affects its <code>z-index</code>:</p> <pre class="lang-js prettyprint-override"><code>var gEnter = svg.enter().append("svg").append("g"); gEnter.append("g").attr("class", "x axis"); gEnter.append("g").attr("class","y axis"); gEnter.append("g").attr("class", "bars"); </code></pre> <p>And finally making the major <code>tickSize</code> on the y-axis <code>-(width - margin.right - margin.left)</code>:</p> <pre class="lang-js prettyprint-override"><code>yAxis = d3.svg.axis() .scale(y) .orient("left") .tickSubdivide(true) .tickPadding(5) .ticks(10) .tickSize(-(width - margin.right - margin.left), 2, 8); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload