Skip to content

[ChartJs] Adding a better way to register Chartjs plugins #870

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

Merged
merged 1 commit into from
May 15, 2023

Conversation

weaverryan
Copy link
Member

@weaverryan weaverryan commented May 12, 2023

Q A
Bug fix? yes
New feature? yes, but in order to fix a bug
Tickets Fix #867 Fix #754 Fix #598 Fix #167
License MIT

The previous method, in npm (and likely in the native browser via importmaps) the Chart would always be imported into the Chartjs UX controller before your userland code would run to register the plugin.

Cheers!

@@ -109,7 +109,11 @@ Then register the plugin globally. This can be done in your ``app.js`` file:
import { Chart } from 'chart.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't you remove this line ?

@@ -213,6 +218,26 @@ Then in your render call, add your controller as an HTML attribute:

{{ render_chart(chart, {'data-controller': 'mychart'}) }}

There is also a ``chartjs:init`` event that is called just *one* time before your
first charts is rendered. That's an ideal place to `register plugins globally <Using Plugins>`_
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
first charts is rendered. That's an ideal place to `register plugins globally <Using Plugins>`_
first chart is rendered. That's an ideal place to `register plugins globally <Using Plugins>`_


// assets/app.js

import { Chart } from 'chart.js';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This import looks useless to me, as the code snippet does not use it

@weaverryan
Copy link
Member Author

Good catches - thank you Stof!

@weaverryan weaverryan force-pushed the fix-chartjs-plugin-registeration branch from fc28684 to ab5f111 Compare May 15, 2023 10:42
@weaverryan weaverryan merged commit a4763d7 into symfony:2.x May 15, 2023
@Matoto951
Copy link

Sorry to post this here, but how am I able to fetch this update to my project? And thx @weaverryan for the quick fix!

@weaverryan
Copy link
Member Author

Change your version in composer.json to 2.x-dev :)

@weaverryan weaverryan deleted the fix-chartjs-plugin-registeration branch May 15, 2023 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants