I am trying to use chart-js and react-chartjs-2 but is showing following error:
Failed to compile.
./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'
my code:
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: true,
},
},
],
},
};
return (
<div>
<Bar data={data} options={options} />
</div>
);
}
export default ChartData;
installed dependencies:
"chart.js": "^2.9.4", "react-chartjs-2": "^3.0.3"