Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Bar chart with time axis set wrong bar width and position #4745

Closed
andreafi opened this issue Sep 12, 2017 · 6 comments
Closed

[BUG] Bar chart with time axis set wrong bar width and position #4745

andreafi opened this issue Sep 12, 2017 · 6 comments

Comments

@andreafi
Copy link

Creating a bar chart with non consecutive date (or date with differente distances) the chart draw bars with different width and wrong positions.

image

Here the example:

https://codepen.io/andreafi/pen/RLbjzJ

@etimberg
Copy link
Member

This works in v2.7 if you add distribution: 'series' to the x axis configuration. Check out http://www.chartjs.org/samples/latest/scales/time/financial.html

@andreafi
Copy link
Author

Thanks eimberg, but your solution doesn't solve the problem, because it changes the X axis.
This is the result of distribution: 'series' option:

image

I need to mantain the X axis linearity and have the bars with same width.
Thanks for your support.

@phyopyae
Copy link

It is also same problem in my environment.
If distribution is 'series' and ticks.source is 'auto', the bar can't display with series. It will skip the not exist X-axis value.

@Darkrender
Copy link

Darkrender commented Nov 20, 2017

This issue should really be re-opened as we are having the exact same problem over two months later and it has not been resolved. This was closed pre-maturely, especially since the given example doesnt work. This issue alone means we will probably have to look for a different chart library if there is no workaround

@simonbrunel
Copy link
Member

Re-opening: as discussed in #4911, we should support data at different distances with same bar width but we still need to figure out what the proper way to determine the bar width to use (I'm working on it).

The only workaround I'm thinking of is to set barThickness or maxBarThickness in the scale options but it's not ideal since it's not relative to the chart size.

@benmccann
Copy link
Contributor

Yeah, I don't think that barThickness or maxBarThickness is would work unfortunately though I understand the appeal.

barThickness would be really hard for a user to set because it's based on a number of factors. A user would have to set it to something like barThickness: 0.8 * (chart.scales.xAxes[0].maxPixel - chart.scales.xAxes[0].minPixel) / chart.data.datasets[0].data.length. And that's assuming those are attributes that are even possible for a user to access. And I don't think you could even do that before the chart was drawn, so a user would have to draw it once, then set the value, then update. And what if you have a responsive chart. Then you need to attach a listener and update the barThickness everytime the page is resized

I think we would really need to add an option like equallySizedBars or something along those lines. It just becomes much too hard to use if we try to do anything else

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants