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

Padding and lineHeight has no effect #153

Open
aldipower opened this issue Oct 10, 2019 · 8 comments
Open

Padding and lineHeight has no effect #153

aldipower opened this issue Oct 10, 2019 · 8 comments

Comments

@aldipower
Copy link

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.

@simonbrunel
Copy link
Member

Hi @aldipower. padding should work, can you please create a codepen / jsfiddle that reproduces your issue with the latest version so we can debug what's going wrong.

@jamieburchell
Copy link

jamieburchell commented Mar 11, 2020

Did this ever get resolved? Same issue with the latest version. Line height and padding do nothing.

@teawithfruit
Copy link

teawithfruit commented 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/

@jamieburchell
Copy link

FYI My project was using a custom font: Open Sans

@fehays
Copy link

fehays commented Apr 3, 2020

I'm having the same problem. No custom font. However, I noticed if you just supply a number to padding, it does have an affect. It appears to add right padding
padding: 20

@BaltasisKivis
Copy link

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;
    }
}

@mathias22osterhagen22
Copy link

Got some similar problem, the padding.bottom stopped to work suddently (I'm using Vue.js) fixed it with a :

 options: {
          plugins: {
            datalabels: {
              formatter: value => value+ "\n\n"
            },
          },
        },

@DaltonKirkCrafted
Copy link

DaltonKirkCrafted commented Jan 19, 2024

I'm having the same issue on version 2.2.0 on a horizontal bar chat. I want to add vertical padding to my labels but it has no effect.

datalabels: {
    align:  'start',
    anchor: 'end',
    clamp: true,
    textAlign: 'left',
    labels: {
      valueLabel: {
        formatter: this.formatLabel,
        color: this.calcColor,
        padding: {
          bottom: 50
        }
      },
      valuePercentageLabel: {
        formatter: this.formatLabelPercentage,
        font: {
          weight: 700
        },
        color: this.calcColor
      }
    }
  }

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

8 participants