Fix Chart.js v3 compatibility#30
Conversation
Chart.js seems to use `Chart.register`, while v2 uses `Chart.plugins.register`. This fixes registering the Color Schemes Plugin in Chart.js v3.
|
I think this is already covered by this one? #26 |
|
Oh I see, you're right. @nagix any chance we can get eyes on this? |
|
Any update on this @nagix ? We are looking to get on Chart.js v3 but right now this lib is preventing us from upgrading |
|
Hi @nagix any news on this? would be good to get this out so that we can get colorscheme to work with v3 :) |
| // Chart.js v3 uses "Chart.register", while v2 uses "Chart.plugins.register" | ||
| const registerPlugin = Chart.register || Chart.plugins.register; | ||
| registerPlugin(ColorSchemesPlugin); | ||
|
|
There was a problem hiding this comment.
I think a better solution would be to remove the automatic registration or to do it only for v2 users
| // Chart.js v3 uses "Chart.register", while v2 uses "Chart.plugins.register" | |
| const registerPlugin = Chart.register || Chart.plugins.register; | |
| registerPlugin(ColorSchemesPlugin); |
Other plugins no longer do automatic registration because it registers the plugin globally. It's preferred to be able to register it on a per-chart basis. For example, see https://chartjs-plugin-datalabels.netlify.app/guide/getting-started.html#registration
There was a problem hiding this comment.
Sounds reasonable from a developers perspective and I'd be fine with that, too. Though here are some reasons, why it might make sense to stay with the global registration:
- Pattern of the Zoom Plugin
I took the Zoom Plugin as it's quite a basic plugin and it's hosted inside thechartjsGitHub organization. They're still registering the plugin globally as of https://github.com/chartjs/chartjs-plugin-zoom/blob/master/src/index.js#L4 . - Simple Usage
Similar to the Zoom Plugin this one is likely to be used by developers with less knowledge. Therefore it might make sense to simplify the getting started process. - Backwards Compatibility
Keeping global registrations allows for in-place upgrades from Chart.js 2.
There was a problem hiding this comment.
The zoom plugin has two entry points. The UMD entry point auto-registers. The ESM one does not: https://github.com/chartjs/chartjs-plugin-zoom/blob/master/src/index.esm.js
If we want to follow that plugin, then we should have two entry points here as well rather than forcing all users to auto-register
|
looks like there is some more that needs to be fixed before you can use this with V3, in V3 the way of import Chart.js has changed with Treeshaking so Also |
Colorschemes plugin is not compattible with V3. Issue about it: nagix/chartjs-plugin-colorschemes#28 Open PR for improving V3 compatability: nagix/chartjs-plugin-colorschemes#30
Colorschemes plugin is not compattible with V3. Issue about it: nagix/chartjs-plugin-colorschemes#28 Open PR for improving V3 compatability: nagix/chartjs-plugin-colorschemes#30
Chart.js seems to use
Chart.register, while v2 usesChart.plugins.register.This fixes registering the Color Schemes Plugin in Chart.js v3.