chartjs / chartjs/Chart.js

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

Open
#10,938 4 comments 2 reactions 0 assignees View on GitHub
type: documentation
Dominant language
JavaScript
Stars
67.7k
Forks
11.9k
Avg merge
7h 39m
Merged PRs (30d)
5

Description

### 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](https://www.chartjs.org/docs/latest/samples/advanced/derived-chart-type.html#derivedbubble-implementation) 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](https://github.com/reactchartjs/react-chartjs-2/issues/1014), [ex2](https://github.com/chartjs/Chart.js/issues/9769)) 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 ]((https://www.chartjs.org/docs/latest/samples/advanced/derived-chart-type.html#derivedbubble-implementation)) 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_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.