ChartJS core.js:4197错误类型错误:不是一个构造函数

yi0zb3m4  于 2022-11-06  发布在  Chart.js
关注(0)|答案(3)|浏览(169)

我在使用chartJS和primeNG时遇到此错误:

  1. ERROR TypeError: chart_js__WEBPACK_IMPORTED_MODULE_2__ is not a constructor
  2. at UIChart.initChart (primeng-chart.js:48)
  3. at UIChart.ngAfterViewInit (primeng-chart.js:29)
  4. at callHook (core.js:3038)
  5. at callHooks (core.js:3008)
  6. at executeInitAndCheckHooks (core.js:2960)
  7. at refreshView (core.js:7243)
  8. at refreshComponent (core.js:8326)
  9. at refreshChildComponents (core.js:6965)
  10. at refreshView (core.js:7222)
  11. at refreshEmbeddedViews (core.js:8280)

在我的angular.json文件中,我添加了:“脚本”:[“节点_模块/图表. js/分销商/图表. js”]
ChartJS版本:“图表. js”:“^3.0.2”,灌注NG:“primeng”:“^11.3.2”,Angular 命令行界面v:“@Angular /倾斜”:“~10.0.1”、

2uluyalo

2uluyalo1#

高概率primeng仍然只适用于chart.js的v2,因为v3本月刚刚发布,并有一些突破性的变化。
将chart.js降级到版本2.9.4应该可以解决您的问题

sg24os4d

sg24os4d2#

变更:

  1. import chart from 'chart.js'

收件人:

  1. import {chart} from 'chart.js'
r6vfmomb

r6vfmomb3#

康格

  1. import Chart from 'chart.js'

进入

  1. import { Chart, registerables } from 'chart.js';
  2. import 'chartjs-adapter-moment'; // or another adapter to avoid moment
  3. Chart.register(...registerables);

here开始。

相关问题