-
Notifications
You must be signed in to change notification settings - Fork 467
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
Chart defaults are global instead of chart specific #8
Comments
Unfortunately it's not as straightforward as it should. I think the cleanest solution would be to globally unregister the plugin and add it locally to some charts: // search for the datalabels plugin
var datalabels = Chart.plugins.getAll().filter(function(p) {
return p.id === 'datalabels';
})[0];
// globally unregister the plugin
Chart.plugins.unregister(datalabels);
var chart = new Chart('chart-id', {
type: 'line',
data: { ... },
options: {
plugins: {
datalabels: {
// plugin options ...
}
}
},
plugins: [
datalabels //< this will add the plugin locally
]
}); Another solution would be to disable the plugin globally with // backup plugin defaults
var datalabels_defaults = Chart.defaults.global.plugins.datalabels;
// disable the plugin for all charts
Chart.defaults.global.plugins.datalabels = false;
var chart = new Chart('chart-id', {
type: 'line',
data: { ... },
options: {
plugins: {
datalabels: Chart.helpers.merge({}, [datalabels_defaults, {
// plugin options ...
}])
}
}
}); Finally, |
I decided to go with your first solution, thanks for the quick reply! |
I have been trying to find out a way to achieve what you are looking for.. I got settled on this very simple solution.. You need to turn off the plugin for the chart which you want labels on like this:
|
|
For anyone looking for the solution, i think there is a little typo, what worked for me was |
This sadly doesn't work for me. |
I have a page with multiple charts, I want to use this plugin with one specific chart and not with the others. Because the defaults are global my other charts are still using the plugin.
I fill the options with this plugin's configuration for one chart and not the others, the datalabels still show up on all my charts.
A workaround is to set Chart.defaults.global.plugins.datalabels.display = false; so it doesn't show the values. I'd like a cleaner options so I can set this chart specific, is this possible?
The text was updated successfully, but these errors were encountered: