首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Chart.register不是一个函数

Chart.register不是一个函数
EN

Stack Overflow用户
提问于 2022-03-18 13:07:08
回答 1查看 3.9K关注 0票数 4

我正在尝试这个reactjs流图https://nagix.github.io/chartjs-plugin-streaming/latest/tutorials/react/app.html的例子

但是,我似乎无法使它工作,它编译没有问题,但没有在浏览器中显示任何东西,当我检查浏览器控制台时,它有错误消息,上面写着:

代码语言:javascript
复制
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),然后错误消息是:

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2022-03-18 13:28:17

您需要从chart.js而不是从2导入图表,这样才能注册它:

代码语言:javascript
复制
import {Chart} from 'chart.js';
import {Chart as ReactChart} from 'react-chartjs-2';
import StreamingPlugin from 'chartjs-plugin-streaming';

Chart.register(StreamingPlugin);
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/71527519

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档