缺少类属性转换,使用 react-chartjs-2 时出错

问题描述 投票:0回答:0

我想在 React js 中使用 chart.js 安装包并导入项目后,我遇到了这个错误:

.../node_modules/chart.js/dist/chart.js:缺少类属性转换

class DatasetController {
> 568 |  static defaults = {};
      |  ^^^^^^^^^^^^^^^^^^^^^
  569 |  static datasetElementType = null;
  570 |  static dataElementType = null;
  571 |  constructor(chart, datasetIndex){
    at transformFile.next (<anonymous>)
    at run.next (<anonymous>)
    at transform.next (<anonymous>)

我的代码:

import React from "react";
import {
    Chart as ChartJS,
    CategoryScale,
    LinearScale,
    PointElement,
    LineElement,
    Title,
    Tooltip,
    Legend,
  } from 'chart.js'
import { Line } from 'react-chartjs-2'

ChartJS.register(
  CategoryScale,
  LinearScale,
  PointElement,
  LineElement,
  Title,
  Tooltip,
  Legend
)

export default function LineChart({...props}) {
  const { data, options } = props

  return (
    <React.Fragment>
      <Line options={options} data={data} />
    </React.Fragment>
  )
}
reactjs chart.js react-chartjs-2
© www.soinside.com 2019 - 2024. All rights reserved.