正在使用Next.js开发用户仪表板应用程序。我从节点和MongoDB服务器查询我的客户端。我需要使用chart.js加载我的图表。但是当我运行代码时,我会遇到这样的错误。TypeError: chart_js.Chart.register不是一个函数。下面是代码片段:
import {Chart as ChartJS} from 'chart.js';
import { Bar } from 'react-chartjs-2';
import React, { useEffect, useReducer } from 'react';
import Layout from '../../components/Layout';
import { getError } from '../../utils/error';
ChartJS.register(
CategoryScale,
LinearScale,
BarElement,
Title,
Tooltip,
Legend
);发布于 2022-07-05 08:46:15
2)您没有导入所有要注册的元素,而且由于Chart.register不是一个函数,我怀疑您使用的是非树性的V2 of Chart.js。所以你不能也不需要使用寄存器来显示图表,除非你要升级到V3并使用树搜索
如果您想在V2中注册任何插件,您需要在图表的插件上注册它们,如下所示:
Chart.plugins.register(plugins);https://stackoverflow.com/questions/72865511
复制相似问题