Search code examples
d3.jsscalepadding

domain / padding in d3.js linear scales


Folks-

I've been trying to set the d3.scale.linear.domain x axis value manually, using Mike Bostock's simple bar chart: http://bl.ocks.org/mbostock/raw/2368837/

 var x = d3.scale.linear()
     .domain([-100, 200]) //this line added
     .range([0, width])

I would expect this to yield a an x axis with values -100 to 200. Instead it yields -30 to 10, as before, and the chart doesn't change. Any ideas?

Thanks,

RL


Solution

  • The domain is set again inside the d3.tsv callback:

    x.domain(d3.extent(data, function(d) { return d.value; })).nice();
    

    If you want to change it, you need to delete that line.