我试着在codesandbox中做到这一点:
const Chart = require("chart.js");
plot() {
this.chart = new Chart(this.chartRef.current, {
..
}
]
}
});
}但是,我在require上得到一个错误:
Cannot find name 'require'.和那个Chart is not a constructor
我还尝试将其替换为
import Chart from chart.js但这也不起作用。我怎样才能修复我的codesandbox?这里有一个链接
https://codesandbox.io/s/opur8?file=/src/Graph.tsx:2009-2333
发布于 2021-04-28 19:46:50
要加载和注册所有内容,请尝试:
import Chart from 'chart.js/auto';...which是...的缩写
import { Chart, registerables } from 'chart.js';
Chart.register(...registerables);反过来,...which是单独导入和注册每个部件的缩写。有关更多示例,请参阅documentation。
发布于 2021-04-28 20:16:47
Chart类作为命名导出导出。
用法:import {Chart} from 'chart.js'
https://stackoverflow.com/questions/67299528
复制相似问题