简体   繁体   中英

yAxes not re-render new data in Chart.js with React.js

Hi I try using the Line chart in my project but get an error you can see it in the image below

package.json

"dependencies": {
  "chart.js": "^3.7.1",
  "react": "^17.0.2",
  "react-chartjs-2": "^4.1.0",
  "react-dom": "^17.0.2",    
},

Chart code

 const data = {
        labels: coinTimeStamp,
        datasets: [
            {
                label: 'Price in USD.',
                data: coinPrice,
                fill: false,
                backgroundColor: '#0071bd',
                borderColor: '#0071bd'
            }
        ]
    }

    const options = {
        scales: {
            yAxes: [
                {
                    ticks: {
                        beginAtZero: true
                    }
                }
            ]
        }
    }

<Line data={data} options={options}  />

and I get these two errors in the browser console

在此处输入图像描述

and thanks

add the following to the import section

import {
    Chart as ChartJS,
    CategoryScale,
    LinearScale,
    PointElement,
    LineElement,
    Title,
    Tooltip,
    Legend,
} from 'chart.js';

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

this will fix the issue

and this---

for Invalid scale config. for scale: yAxes, I removed the first array, I think it was and left it like this:

const options = { scales: { y: { ticks: { beginAtZero: true, }, }, }, };

https://github.com/adrianhajdin/project_cryptoverse/issues/26

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM