Chart.js icon indicating copy to clipboard operation
Chart.js copied to clipboard

Register every used element again in custom charts (mentioned anywhere?)

Open J4L0 opened this issue 3 years ago • 4 comments

Documentation Is:

  • [X] Missing or needed?
  • [x] Confusing
  • [ ] Not sure?

Please Explain in Detail...

I was about to extend an existing chart type with an extension like class Custom extends BubbleController and then register it Chart.register(Custom);, according to the example given.

But unlike what was written in the given example I realized, that you have to re-register all elements you're using or the following error appears Uncaught Error: "..." is not a registered element / scale / .. .

Others ran into the same issue (ex1, ex2) but I couldn't find anything mentioned about it in the documentation. Would be nice to add this.

I was using version 3.9.1 when I encountered the error message.

Thx!

Your Proposal for Changes

For example in the "New Charts" documentation change

// Stores the controller so that the chart initialization routine can look it up Chart.register(Custom);

to

// Stores the controller so that the chart initialization routine can look it up // All other used elements and scales must also be re-registered, for the custom chart to work correctly. Chart.register(Custom, LineElement, PointElement, RadialLinearScale);

Example

No response

J4L0 avatar Dec 05 '22 10:12 J4L0

Do you have an example of where you need to re register components because this should not be the case, when you register your elements with Chart.Register they are registererd globally so you only need to do that once.

LeeLenaleee avatar Dec 06 '22 10:12 LeeLenaleee

I was using the example given on the documentation page and registered the custom object accordingly. If I do this, I receive the error:

chart.mjs:4009 Uncaught Error: "..." is not a registered scale. at Registry._get (chart.mjs:4009:13) at Registry.getScale (chart.mjs:3964:17) at chart.mjs:5592:37 at each (helpers.segment.mjs:60:12) at Chart.buildOrUpdateScales (chart.mjs:5579:5) at Chart._updateScales (chart.mjs:5726:10) at Chart.update (chart.mjs:5687:10) at new Chart (chart.mjs:5476:12) at main.js:208:19

So telling me, even doe I didn't customize (for ex.) the scale I have to re-register the default scale as well as all other Elements. This problem resolves when I register all elements "controller, line, point, scale" and replace the defaults with the customized ones.

UPDATE: I also had to add the built in plugins for them to work (eg. Tooltip). No Idea if I made a mistake somewhere. UPDATE 2: I also lose all pre-integrated plugins. "Colors" (for backgroundColor), etc. are also not available anymore and I don't know how to register them again.

Here the example.

J4L0 avatar Dec 12 '22 09:12 J4L0

Sample might indeed be confusing if looked without checking integration guide

Even though not standing-out, the procedure to register everything (or only what is wanted) is documented here (and here for 3.9.1, but still the same, except that you can also use ...registerables which I assume would be the same as chart.js/auto)

Nonetheless, for future purpose, maybe put a disclamer on example might be an Idea, or we can also accept that the example is minimal

Nico-DF avatar Dec 16 '22 11:12 Nico-DF

Ah! Thank you!

I see. I think, that this should be said in the context of custom charts, etc. I wouldn't have come up with looking under "Integration" when I try to create my own charts.

I feel like, I would consider reading through the integration section when just using the library as it is.

J4L0 avatar Dec 16 '22 12:12 J4L0