Gha*_*MJT 7 reactjs chart.js react-chartjs-2
我正在尝试这个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
Run Code Online (Sandbox Code Playgroud)
我尝试了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
Run Code Online (Sandbox Code Playgroud)
您需要从 Chart.js 而不是从 Reacht-chartjs-2 导入 Chart 来注册它,如下所示:
import {Chart} from 'chart.js';
import {Chart as ReactChart} from 'react-chartjs-2';
import StreamingPlugin from 'chartjs-plugin-streaming';
Chart.register(StreamingPlugin);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10097 次 |
| 最近记录: |