title: Calculating the number of bars in a bar chart in dc.js
body: <p>I want to adjust width of bar charts based on number of bars appearing on my bar chart. Here is my chart which is displaying enough records which are fit to the width and is displayed nicely. <a href="https://i.stack.imgur.com/g4pQX.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/g4pQX.png" alt="enter image description here"></a></p>
  
  <p>Here is another scenario in which only two bars are displayed in same width, Which looks odd. <a href="https://i.stack.imgur.com/A2Rzg.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/A2Rzg.png" alt="enter image description here"></a></p>
  
  <p>For this situation I need to adjust the width of charts according to the number of bars, so that my chart will look pretty.</p>
  
  <p>Here is the part of my script</p>
  
  <pre><code>var width = ??;   // Here how should I calculate width based on the number of bars? 
  redrawCustomerCodeBarChart
          .width(width)
          .height(400)
          .margins({top: 10, right: 10, bottom: 70, left: 30})
          .dimension(customerNamer)
          .group(customerNameGroupr)
          .x(d3.scale.ordinal().domain(newCoh.map(function (d) {return d.customerName; })))
          .xUnits(dc.units.ordinal)
          .elasticY(true)
          .renderHorizontalGridLines(true)
          .on('renderlet',function(chart){
                chart.selectAll("g.x text")
                  .attr('dx', '-15')
                  .attr('transform', "rotate(-55)");
              })
           .on('filtered.monitor', function(d) {
                 // return d.key + ' (' + d.value + ')';
                 if(d.value !== undefined)
                  size= d.value;
              })
          .controlsUseVisibility(true);
  </code></pre>