title: d3 bar chart with fixed bar width and fixed spacing to align in center axis line
body: <p>I know it's little weird, I do have a requirement to have bar chart with fixed width instead of dynamic width handling. This is implemented with below code by handling <code>x</code> and <code>width</code>, now the spacing between the bars more when there is only few bars. So is there any possibility in d3 to render x axis values and chart in center of the axis line with fixed bar width and fixed spacing between bars?</p>
  
  <pre><code>bars.append('rect')
  .attr('class', function(d,i) {
      return 'bar';
  })
  .attr('id', function(d, i) {
      return name+'-bar-'+i;
  })
  .attr('x', function(d) { 
      return xScale(d.month) + (xScale.rangeBand() - 15)/2;
  })
  .attr('width', function(){
      return Math.min(xScale.rangeBand()-2, 15);
  })
  .attr('y', function(d) { return yScale(d.set.count); })
  .attr('height', function(d) { return height - yScale(d.set.count); })
  .on('click', function(d, i) {
    //
  });
  </code></pre>
  
  <p><a href="https://jsfiddle.net/betasquirrel/9auqfbLu/1/" rel="nofollow noreferrer">fiddle</a></p>