Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

minBarLength documentation is incorrect

Open Xyloking17 opened this issue 4 years ago • 8 comments

I was having trouble getting the minBarLength to work. After looking online for a solution I found #6212. In there Everybody was using the minBarLength in the scales options. I tried it out and this works, but in the documentation it shows the property being used in the dataset object

Xyloking17 avatar Mar 02 '20 17:03 Xyloking17

What version of Chart.js are you using? I believe if you're using the latest (2.9.3) it should work in either location

benmccann avatar Mar 03 '20 02:03 benmccann

@benmccann I'm currently using version version 2.8.0 so I'll give it a try in 2.9.3 and see if it works

Xyloking17 avatar Mar 03 '20 21:03 Xyloking17

Cannot get the minBarLength setting to work to, it just doesn't have any effect. I am using 2.9.3 and having the option in the dataset configuration.

minBarLength This image illustrates the problem. The February month should be shown with a minBarLength of 2 pixels set in my dataset config. I tried other places like the scales config too..

This issue should be reopened: https://github.com/chartjs/Chart.js/issues/6212

aldipower avatar Apr 19 '20 20:04 aldipower

I believe that minBarLength makes a small bar starting at zero in the same direction as the sign of the value (in the positive direction if the value is zero). This can cause the bar to not show up in a couple of situations:

  • Aldipower's example, where 2 pixels is probably well less than the length that is necessary to hit 22 on the Y axis. A workaround is to include zero in the scale, perhaps via beginAtZero. This changes the look of the chart, but maybe that's better than showing a small bar at 22 when the actual value is probably well below that. Maybe some kind of arrow indicating that the value is "somewhere down there" could be shown?
  • My problem, where all my values are negative or zero, so the bar is above zero and so is clipped. The workaround I'm using is to set a small positive suggestedMax. It would be nice to instead have a fix where the minibar went in the negative direction for this case, as discussed in #6982.

fds-github avatar Jul 17 '20 13:07 fds-github

It seems the problem here is that minBarLength always increases the size for 0 on the value axis. In https://jsfiddle.net/174aquk2/ it should apply from the base value to ensure that the middle bar appears.

@kurkle I think this should be an easy fix. Thoughts?

etimberg avatar Oct 18 '20 03:10 etimberg

I think this one is more related to the beginAtZero, that we already changed to default for true for bar charts. The minBarLenght correctly applies, its just not visible.

image I'd think the image above would be very misleading if the data was [23, 0, 25]

kurkle avatar Oct 18 '20 08:10 kurkle

Anyway, it would still be feasible to have a visible bar when there is a value even when beginAtZero is false.

minBarLenght could be used to figure out the amount a scale needs to "pad" itself to some direction.

There are some other use cases where I would need a scale to have a certain max value and and a certain amount of pixels to that.

So I'd tend to move this problem to the scale somehow.

kurkle avatar Oct 18 '20 08:10 kurkle

This is much closer with v3.7.1 but still requires one extra setting to manually set the base value of the dataset to the minimum y axis value. https://jsfiddle.net/2bw8gv0y/

etimberg avatar Feb 13 '22 17:02 etimberg