小编Rav*_*jee的帖子

无法解析“chart.js/auto”

我正在尝试使用 Chart-js 和 React-chartjs-2 但显示以下错误:

编译失败。

./node_modules/react-chartjs-2/dist/index.modern.js
Module not found: Can't resolve 'chart.js/auto' in 'C:\Users\An\chart-react\project-folder\client\node_modules\react-chartjs-2\dist'
Run Code Online (Sandbox Code Playgroud)

我的代码:

import React from "react";
import { Bar } from "react-chartjs-2";

function ChartData() {
  const data = {
    labels: ["1", "2", "3", "4", "5", "6"],
    datasets: [
      {
        label: "# of Votes",
        data: [12, 19, 3, 5, 2, 3],
        fill: false,
        backgroundColor: "rgb(255, 99, 132)",
        borderColor: "rgba(255, 99, 132, 0.2)",
      },
    ],
  };

  const options = {
    scales: {
      yAxes: [
        {
          ticks: {
            beginAtZero: …
Run Code Online (Sandbox Code Playgroud)

frontend reactjs chart.js react-chartjs react-chartjs-2

2
推荐指数
1
解决办法
3090
查看次数