1

Using dc.js, I want to keep the size of the bar constant on my bar chart.

The number of bars may vary from 1 to 10. Currently when there is only one bar it occupies the complete chart space.

I tried limiting the bar width by adding

MAX_BAR_WIDTH = 250;

but now the ticks and bar position do not match.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Pranav Asthana
  • 892
  • 1
  • 9
  • 21
  • Please share working fiddle? May be this link will help https://stackoverflow.com/questions/15191258/properly-display-bin-width-in-barchart-using-dc-js-and-crossfilter-js – Aravind Cheekkallur Sep 28 '17 at 08:31

1 Answers1

0

Automatic calculation of the domain is a feature which can be turned off. The bar width will be calculated based on the domain and the number of bars which can be shown in that domain.

You should probably set the x domain manually and turn off "elastic":

var minX, maxX; // calculate these however you want
chart
    .x(d3.scale.linear().domain([minX, maxX])
    .elasticX(false)

Documentation:

Gordon
  • 19,811
  • 4
  • 36
  • 74