Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Chart.register is not a function

I'm trying this example of reactjs Streaming chart https://nagix.github.io/chartjs-plugin-streaming/latest/tutorials/react/app.html

but I can't seems to make it work, it compile without problem but dosnt show anything in the browser, and when I check the browser console it has error message that says:

App.js:7 Uncaught TypeError: react_chartjs_2__WEBPACK_IMPORTED_MODULE_5__.Chart.register is not a function
    at Module../src/App.js (App.js:7:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/index.js (App.js:46:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at startup:7:1
    at startup:7:1
./src/App.js    @   App.js:7
options.factory @   react refresh:6
__webpack_require__ @   bootstrap:24
fn  @   hot module replacement:61
./src/index.js  @   App.js:46
options.factory @   react refresh:6
__webpack_require__ @   bootstrap:24
(anonymous) @   startup:7
(anonymous) @   startup:7

I tried Chart.plugins.register(StreamingPlugin), then the error message is:

App.js:7 Uncaught TypeError: Cannot read properties of undefined (reading 'register')
    at Module../src/App.js (App.js:7:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at fn (hot module replacement:61:1)
    at Module../src/index.js (App.js:46:1)
    at Module.options.factory (react refresh:6:1)
    at __webpack_require__ (bootstrap:24:1)
    at startup:7:1
    at startup:7:1
./src/App.js    @   App.js:7
options.factory @   react refresh:6
__webpack_require__ @   bootstrap:24
fn  @   hot module replacement:61
./src/index.js  @   App.js:46
options.factory @   react refresh:6
__webpack_require__ @   bootstrap:24
(anonymous) @   startup:7
(anonymous) @   startup:7
like image 987
GhaDa MJT Avatar asked Jul 02 '26 12:07

GhaDa MJT


1 Answers

You need to import Chart from chart.js and not from Reacht-chartjs-2 to register it like so:

import {Chart} from 'chart.js';
import {Chart as ReactChart} from 'react-chartjs-2';
import StreamingPlugin from 'chartjs-plugin-streaming';

Chart.register(StreamingPlugin);
like image 66
LeeLenalee Avatar answered Jul 05 '26 17:07

LeeLenalee