-
Notifications
You must be signed in to change notification settings - Fork 488
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
Gradient not applied #114
Comments
@simonbrunel I see you marked this issue as Enhancement. But reading the published documentation: Style OptionsStyle options are usually inputs for The following values are supported:
Therefore my expectation was that capability was already ready and then this is a bug and not an enhancement. Am I wrong? |
@stockiNail I flagged this ticket but forgot to reply, sorry. This is already implemented but the gradient is applied locally to each label, not globally and I guess that's why you don't see it. Both use cases are valid so that's why I don't consider your request as a bug but as an enhancement. |
Perfect |
I did some tests. Setting globally and it does not work (as written above): Chart.defaults.global.plugins.datalabels.backgroundColor = gradientStroke;
Chart.helpers.merge(Chart.defaults.global.plugins.datalabels, {
backgroundColor: gradientStroke
}); Then we have already seen that setting the gradient at chart options level (both directly or by callback) it does not work. Then, thinking about the reply (where datasets: [{
backgroundColor: gradientStroke,
borderColor: gradientStroke,
data: Samples.numbers({
count: DATA_COUNT,
min: 0,
max: 100
}),
datalabels: {
backgroundColor: gradientStroke
}
}] But it does not work, also using the callback. Is there any sample to have a look? |
I agree that my previous comment is confusing. What I mean by "local" is that the gradient coordinates are relative the the label coordinates (example), not relative to the canvas coordinates (global). So currently, it's not possible to implement your use case (thus the "enhancement"). |
Ah ok, now I've understood. THANK YOU About my use case, nop, I can wait. I'll release my project in next days, adding this condition for using gradients. |
Thank you for feedback and examples! VERY HELPFUL!!! And the workaround is not so bad... I'm gonna to implement it! Let me share the context. I'm developing a GWT wrapper for CHART.JS (named Charba and you recognize parts of documentation) where I've included Datalabels as component. My use case is not a specific need (in fact I used your public sample) but I'd like to provide the right guidelines for developers who are using Datalabels in Charba in their projects and use gradients! ;) And eithers your samples are very helpful to me!! Chroma sounds interesting... I'll have a look !! Thanks again |
I'm gonna add your samples in the showcase to show how to use gradients with the plugin! |
@simonbrunel just FYI. I used your first sample and it works by Charba. This is not an issue but an enhancement, fully agree |
Thanks @stockiNail for the extra details about the context, it looks really great. |
FYI I have added the way to get the color from a gradient as you did by Chroma. THKS! Really appreciated! In this way I've got also another workaround. I've update the sample in jsfiddle as following: backgroundColor: function(ctx) {
var count = ctx.dataset.data.length;
var ratio = count > 1 ? ctx.dataIndex / (count-1) : 0;
return chroma.mix(c1, c0, ratio);
}, |
I'm trying to apply a gradient as background color to labels but it doesn't work.
Here is code, based on data labels sample:
Here is the result:
There is a similar issue in Chart.js, fixed in the master .
The text was updated successfully, but these errors were encountered: