0

Getting error after setting up chart component in react.

Error:

enter image description here

Code:

import React, {useEffect, useState} from 'react';

import {Line} from 'react-chartjs-2';

import './EloChart.css';


const EloChart = props => {

  const [chartData,setChartData] = useState({})

  const chart = () => {
    setChartData({
      labels: ['december','january','february','march','april'],
      datasets: [
        {
          label: 'elorating',
          data: [1500, 1600, 1700, 1800, 1900],
          backgroundColor: [
            'rgba(75, 192, 192, 0.6)'
          ]
        }
      ]
    })
  }

  
  useEffect(()=> {
    chart()
  }, [])

  return (
    <section className="elo-chart" >
      <h2>Elo Chart</h2>
        <Line data={chartData}/>
    </section>
  );
};

export default EloChart;

Package.json:

  "dependencies": {
    "chart.js": "^3.1.0",
    "react": "^16.8.6",
    "react-chartjs-2": "^2.11.1",
    "react-dom": "^16.8.6",
    "react-scripts": "3.0.1"

1 Answer 1

2

The react wrapper is not updated yet to support chartjs version 3 so you will have to downgrade to version 2.9.4.

If you change "chart.js": "^3.1.0", to "chart.js": "^2.9.4", and run your install command again it will work

Sign up to request clarification or add additional context in comments.

1 Comment

Thats true, i found it few minutes ago. Thank you for your reponse!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.