Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The x function usually scales from your data domain to the range needed which is often the width of your chart. This is how you'll find things in many examples.</p> <p>Usually to create axes, you pass to d3.svg.axis() your x function. However, the main job of the x function is often to create, in my case, the bars of a bar chart.</p> <p>My own x function that I'm using in this bar chart:</p> <pre><code>var x = d3.scale.linear() .domain([0, data.length]) .rangeRound([0, width]); </code></pre> <p>Here's one from <a href="http://bl.ocks.org/mbostock/7441121" rel="nofollow">MBostock</a>:</p> <pre><code>var x = d3.scale.ordinal() .rangeRoundBands([0, width], .1); </code></pre> <p>And another with a <a href="http://jsfiddle.net/robdodson/KWRxW/" rel="nofollow">JSFiddle</a>:</p> <pre><code>var x = d3.time.scale() .domain([new Date(data[0].date), d3.time.day.offset(new Date(data[data.length - 1].date), 1)]) .rangeRound([0, width - margin.left - margin.right]); </code></pre> <p>Using the power and simplicity of d3 scales, I was able to solve this problem by converting from array indices to dates with a separate x function, xAsTime, like so:</p> <pre><code>var xAsTime = d3.time.scale() .domain([this.start * 1000, this.end * 1000]) .range([0, width]) var xAxis = d3.svg.axis() .scale(xAsTime) .tickSize(-height) .tickPadding(3); </code></pre> <p>As per my question, the only change was to switch the domain and ranges. While I unsure of the details, it seems like the domain of the scale is what is displayed as ticks.</p>
    singulars
    1. This table or related slice is empty.
    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. This table or related slice is empty.
    1. This table or related slice is empty.
    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