c3js / c3

:bar_chart: A D3-based reusable chart library
http://c3js.org
MIT License
9.35k stars 1.39k forks source link

Bar width ratio and tick values/count #1368

Open iamnathadian opened 9 years ago

iamnathadian commented 9 years ago

The bar width ratio does not calculate correctly when the number of ticks is different from the number of columns in a bar chart because of using the x tick values or x tick count options.

Here is an example: http://jsfiddle.net/L7od79g3/1/

The bar width ratio seems to be based on the distance between the ticks. I feel that it would be better if the bar width ratio was relative to the width between the columns instead.

jeremy-doghouse commented 8 years ago

I'm getting the same issue with x values set.

Examples: https://jsfiddle.net/jez500/r4xq1y93/1/

Is anyone aware of any workarounds?

iamnathadian commented 8 years ago

I'm using a formula to calculate the bar.width.ratio. It's something like this:

1 / ( ( ( {number of x columns} - {number of x ticks} ) / {number of x ticks} ) + 0.6 )

For your example, it would look like this: https://jsfiddle.net/r4xq1y93/2/

jeremy-doghouse commented 8 years ago

Thanks heaps @iamnathadian, very helpful!