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

Array tick labels not centered along the bar correctly on horizontal bar charts #5211

Closed
Moghul opened this issue Jan 31, 2018 · 2 comments
Closed

Comments

@Moghul
Copy link

Moghul commented Jan 31, 2018

Expected Behavior

Tick labels can be passed as an array of strings to be represented as multiple lines on a chart. It is expected that the label is then centered vertically to the bar's position.

Current Behavior

The first string in the array is centered to the bar, and subsequent strings are stacked below the first one.

Possible Solution

Count the number of labels and change the initial offset for the labels to be higher by half the array length multiplied by the line height.

Steps to Reproduce (for bugs)

https://jsfiddle.net/qL4rm9an/3/

I'm not sure if I'm missing a setting or something (though I don't see why centering wouldn't be default behaviour)...

Context

I know I can draw my own labels with a homemade plugin but that is not really an option for me. I have situations where potentially dozens of charts are loaded so a solution like that would be potentially very heavy

Environment

  • Chart.js version: 2.7.1, 2.6.0, 2.5.0, maybe others?
  • Browser name and version: Any
  • Link to your project:
@etimberg
Copy link
Member

etimberg commented Feb 1, 2018

That's definitely a bug. I think y needs to be changed just before this loop https://github.com/chartjs/Chart.js/blob/master/src/core/core.scale.js#L860

@MPierre9
Copy link
Contributor

MPierre9 commented Feb 5, 2018

Hello, I'd like to work on this if possible :)

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

3 participants