Global defaults have no effect for doughnuts and pie charts.
Expected behavior
Doughnut and pie charts use global datasets defaults or arc elements defaults for backgroundColor.
Polar area charts scriptable property dataIndex seems dependent on the property type.
Current behavior
The global defaults have no effect. Scriptable options funcitons are not called.
Reproducible sample
https://codepen.io/leelenaleee/pen/WNyJXEe
Optional extra steps/info to reproduce
No response
Possible solution
No response
Context
Testing new Chart.js version for ng2-charts
chart.js version
v4.0.1
Browser name and version
No response
Link to your project
No response
I think this is related to new color plugin of version 4, see https://www.chartjs.org/docs/latest/general/colors.html#per-dataset-color-settings.
I think it's a bug of the plugin, on the following code:
https://github.com/chartjs/Chart.js/blob/82395678024670b0a829b7780c73158ddac27062/src/plugins/plugin.colors.ts#L95-L99
I see 2 things:
- the plugin is using
chart.configbut it doesn't seem to be a proxy therefore doesn't have the fallback to the defaults. It's (AFAIK) the user configuration, ignoring defaults both on controller and elements. -
typeis not used anymore after PR #10904
Nice find, thanks! Given the addition of this new plugin in v4, as a maintainer of the Angular wrapper, I wonder if I should remove the color generation feature and just delegate to the new plugin, any opinions from the Chart.js maintainers?
@santam85 For tests you can disable this plugin by options.plugins.colors.enabled option.
I don't think the colors plugin can resort to fallback colors, because then there always is a color already.
The plugin can also be disabled globally:
Chart.defaults.plugins.colors.enabled = false;
@kurkle exactly what I'm thinking. No options apart disable it, globally.
Yes that's what I did. I can confirm that it fixes my issue, so for now I'll go ahead and disable the color plugin when generating colors myself.
Another option, for the colors plugin, could be to attach as a scriptable global default. But it has performance impact: would always have scriptable options, so no option sharing between elements.
@kurkle for my understanding, do you mean the plugin will set a scriptable option in the defaults? The plugin will just set the scriptable option and the logic is overthere, correct?
Anyway, even if the color plugin is a feature and not a breaking change, I think something could be reported in the migration guide because this is a common use case which is broken. WDYT?
Another option, for the colors plugin, could be to attach as a scriptable global default. But it has performance impact: would always have scriptable options, so no option sharing between elements.
That's what I've gone for in the Angular wrapper lib
I can make a fix for this case.
It is impossible to detect whether the defaults changed or not on the plugin level. So I suggest accepting this as expected behavior and closing the issue.
I think something could be reported in the migration guide
It is a valid problem only for the UMD bundle, where all plugins are enabled by default. We have a notice about that in the docs:
https://www.chartjs.org/docs/latest/general/colors.html
If you are using the UMD version of Chart.js, this plugin will be enabled by default. You can disable it by setting the enabled option to false
@santam85 @stockiNail @kurkle what do you think?
@santam85 @stockiNail @kurkle what do you think?
Fine for me