-
Notifications
You must be signed in to change notification settings - Fork 489
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
datalabel
being clipped/cutted
#427
Comments
Did you find a way? |
@batata004 @frederikhors AFAIK this issue is related to missing space from chart area end and the canvas end. To be able to show the label, you could:
options: {
layout: {
padding: {
right: 60;
}
}
...
}
It should work. |
Another possible solution is to use |
@stockiNail First of all, thank you for your solution. It worked but:
Later, you made another comment that I think is a great idea! Aligning the first label to the right and the last label to the left might solve the problem! The problem is that I am a beginner user with chartjs and I have no idea how to create a custom function to set align based on each point of the graph. Would you mind pointing me in the right direction? |
I discovered! Here is the code.
Anyway, it would be nice for this to be already implemented when clip is set to |
@batata004 I don't like hard coded config as well, mainly if you are using a responsive ui. Nevertheless be aware that many Chart.js options (and also on the plugins/controllers) can be In the documentation, when you see the table with all possible options, there is a column where is indicated if they are scriptable or not. And then there is a section where the input arguments of the callback are explained (usually there is a context). Chart.js: https://www.chartjs.org/docs/latest/general/options.html#scriptable-options That said, the About the code (that's my personal opinion therefore you can ignore) you could avoid all align: function(context) {
if (context.dataIndex === 0) {
return "right";
}
if (context.dataIndex === context.dataset.data.length - 1) {
return "left";
}
return "bottom";
},
Usually the |
@batata004 feel free to close the issue if the solution is ok for your stand point.. |
@stockiNail thanks for all the explanation, now I understand a lot better this awesome library and its customization power (like the scriptable configurations). My only complain is that if Do you think this implementation could be possible in the future inside chartjs or am I dreaming too far? After reading your opinion about this, I will close the thread so you can reply to it. |
@batata004 I understand what you meant. Probably this could be an enhancement even if not simple, I guess.
I image there is a big refactoring for that implementation. I'm collaborating in another plugin (annotation) and the behavior is the same of this one and knowing quite well that code, I can say it could be a long task, time consuming and with an uncertain result. |
@stockiNail Thanks for all the information you provided and indeed this might not be an easy feature to implement, and it looks like too few people would care about it. Better focus the contributor's time in things that matters the most. Thank you a lot for you attention, I wish you a happy 2025 year! |
@batata004 thank you very much and all the best for new year you too! |
Please, check this minimal chart js code to reproduce this problem:
https://www.quemfazsite.com.br/temp/teste.php
Take a look at the righest point labeled "Giassiiiiii". You will see it is cutted/clipped:
I would like the datalabel to only show up if it's not gonna be clipped/cutted, I mean: only show the datalabel if it fits entirely inside the graph. If it does not fit entirely, then dont show it (I prefer not showing than displaying something clipped/cutted).
I tried using setting
clip
to true/false, I tried messing withclamp
andanchor
but nothing works.Thank a lot.
The text was updated successfully, but these errors were encountered: