我正在尝试这个reactjs流图https://nagix.github.io/chartjs-plugin-streaming/latest/tutorials/react/app.html的例子
但是,我似乎无法使它工作,它编译没有问题,但没有在浏览器中显示任何东西,当我检查浏览器控制台时,它有错误消息,上面写着:
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我尝试了Chart.plugins.register(StreamingPlugin),然后错误消息是:
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发布于 2022-03-18 13:28:17
您需要从chart.js而不是从2导入图表,这样才能注册它:
import {Chart} from 'chart.js';
import {Chart as ReactChart} from 'react-chartjs-2';
import StreamingPlugin from 'chartjs-plugin-streaming';
Chart.register(StreamingPlugin);https://stackoverflow.com/questions/71527519
复制相似问题