Padding and lineHeight has no effect
See original GitHub issueHi!
I am trying to vertically center the datalabels in my horizontal bar chart, so they are perfectly vertically aligned in the middle of the bar. As you can see they are a little bit more to the top of the bar. To achieve this I tried to give some padding or a font.lineHeight, but both options have zero effect at all, as they were ignored. I could use the offset with bottom alignment, but this is already used for the left/right positioning of the labels. So not many options are left. Why is the padding not working?
This is my configuration:
datalabels: {
font: {
size: 10,
weight: "bold",
},
clip: true,
anchor: "start",
align: "start",
offset: ({ dataset, dataIndex }) => {
const value = dataset.data[dataIndex];
return value <= 10 ?
0 :
value % 1 ? -39 : -31;
},
formatter: value => localeUtils.toLocaleString(value, "de-DE", 1) + "%",
}
Tried it like that:
datalabels: {
font: {
size: 10,
weight: "bold",
lineHeight: 2,
},
...
}
Or
datalabels: {
padding: { top: 20 }
...
}
Nothing happens.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:1
- Comments:7 (1 by maintainers)
Top Results From Across the Web
Why control padding with line-height? - css - Stack Overflow
The reason for using a line height smaller than 1em is not actually not related to the spacing on top, but rather the...
Read more >How to Tame Line Height in CSS
When a browser encounters the line-height property, what it actually does is take the line of text and place it in the middle...
Read more >Reducing Line Height setting doesn't work in PDF but ... - IBM
We tried to change line height under Spacing and Breaking property to make the text use less space (vertically), but that is not...
Read more >line-height - CSS: Cascading Style Sheets - MDN Web Docs
The line-height CSS property sets the height of a line box. It's commonly used to set the distance between lines of text.
Read more >CSS line-height Property - W3docs
The line-height property has no effect when applying to inline elements: such as images, buttons, etc. Initial Value, normal. Applies to, List items....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
While I’ve created a jsfiddle, the thought occured to me, that this problem can be a part of a custom webfont. Is this possible? To solve this, the line height or padding parameter should be a option.
And here I got the same problem. Both parameter have no effect to the labels. Do you have an idea?
https://jsfiddle.net/bool/xapqvnh3/20/
I’m also using a custom font and ran into the same issue. I’ve solved it by using the formatter and including an empty line before my value. With that, the lineHeight property seems to be working and I’ve managed to center my text vertically