2

I am trying to setup ChartJS with Symfony UX. Since a default datetime adapter is not included with ChartJS 3+, I am getting the following error when using time unit in an axis.

This method is not implemented: Check that a complete date adapter is provided.

How can I add a ChartJS datetime adapter to symfony/ux-chartjs?

I tried importing chartjs-adapter-moment to my app.js, but this adds a second copy of ChartJS module from node_modules/chart.js/dist/chart.mjs to the generated bundle, and registers the adapter to this second copy.

But the symfony ux controller is using its own copy of ChartJS from vendor/symfony/ux-chartjs/assets/node_modules/chart.js/dist/chart.esm.js.

5
  • I've got the same issue, albeit when using the Luxon adaptor. Have you found a resolution? Commented Mar 17, 2023 at 14:43
  • I used moment and Luxon adapter, and it didn't work at first. But later it started working. Not exactly sure, what I changed. Not sure if it was a version conflict. I have moment 2.29.4 and chart.js 3.4.1. In my app.js I have added import 'chartjs-adapter-moment';. Commented Mar 18, 2023 at 7:04
  • Thanks, I'm still having issues with it, despite having the same library versions it seems. If you get chance, could you update the original post with some of your config to see if I can spot a difference with mine? Commented Mar 21, 2023 at 12:51
  • What details do you need? Commented Mar 21, 2023 at 13:33
  • I'd be interested to see your app.js, package.json and any other relevant bits where you prepare the Chart (e.g. to see if you manually load any adapters etc). Commented Mar 21, 2023 at 17:29

1 Answer 1

2

I was facing the same problem and couldn't find an answer. So I asked for some help on Github and we finally found a solution : https://github.com/symfony/ux/issues/1013

So on my project the issue was that it was installing two chart.js

npm why chart.js

And to fix it, I specified this on my package.json :

"chart.js": "^3.4.1 <3.9",

Then I deleted my package-lock.json and run :

npm install

Now you should be able to install date-fns and use 'type' => 'time' correctly with Symfony. Have a look at the link, I detailed the whole manipulation for me. I hope it will help you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.