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

dynamic anchor/alignment/offset support #38

Closed
pingcheng opened this issue Mar 3, 2018 · 2 comments
Closed

dynamic anchor/alignment/offset support #38

pingcheng opened this issue Mar 3, 2018 · 2 comments

Comments

@pingcheng
Copy link

pingcheng commented Mar 3, 2018

Hi,

Is there any way to make the anchor/alignment/offset dynamic but fixed? Like make it a callback or something else?

I am setting up the position of labels in the chart but for some cases the position of labels is not perfect, like the 11% in the pic
screen shot 2018-03-03 at 4 18 06 pm

@simonbrunel
Copy link
Member

You can use scriptable options, for example (jsfiddle):

options: {
  plugins: {
    datalabels: {
      align: function(context) {
        return context.dataset.data[context.dataIndex] < 15 ? 'end' : 'start';
      },
      color: function(context) {
        return context.dataset.data[context.dataIndex] < 15 ? 'black' : 'white';
      }
      // ...
    }
  }
}

@pingcheng
Copy link
Author

pingcheng commented Mar 3, 2018

Thanks! It worked

I tried this way, maybe I missed a comma or other mistakes at that time.

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

2 participants