question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Padding and lineHeight has no effect

See original GitHub issue

Hi! Screenshot_2019-10-10

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:open
  • Created 4 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
teawithfruitcommented, Mar 25, 2020

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/

2reactions
BaltasisKiviscommented, Nov 9, 2020

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

datalabels: {
    color: '#fff',
        anchor :'end',
        align :'start',
        font: {
        size: "18",
            family: "Hind Guntur,sans-serif",
            weight: "600",
            lineHeight: 0.6
    },
    padding: {
        right: 20
    },
    formatter: function(value) {
        return '\n' + value;
    }
}
Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found