我正在尝试react-chartjs-2
在我的项目中使用来创建图表,但出现以下错误:
TypeError: Cannot read properties of undefined (reading 'map')
setDatasets
C:/Users/vivek/code/src/utils.ts:46
43 | currentData: ChartData<TType, TData, TLabel>,
44 | nextDatasets: ChartDataset<TType, TData>[]
45 | ) {
> 46 | currentData.datasets = nextDatasets.map(nextDataset => {
47 | // given the new set, find it's current match
48 | const currentDataset = currentData.datasets.find(
49 | dataset =>
而且,这是我的代码:
import React from "react";
import { Bar } from "react-chartjs-2";
const BarChart = () => {
return (
<div>
<Bar
data={{
labels: ['Red', 'Blue', 'Yellow', 'Green', 'Purple', 'Orange'],
}}
width={600}
height={400}
options={{ maintainAspectRatio: false }}
/>
</div>
);
};
export default BarChart;
我正在尝试创建条形图