Skip to content
Advertisement

How do i use chartjs in react project properly?

Im trying to use chartjs in my react project but it doesnt work. What am i doing wrong?

You can see console logs here:

logs

JavaScript

Advertisement

Answer

The attributes you’re passing to Bar are incorrect. Specifically, your data attribute is missing its own datasets attribute, as can be seen in the error log when Chart.js is attempting to call setDatasets.

Suppose you’re charting the temperature for each day of the past week:

Your labels attribute:

JavaScript

Your data attribute:

JavaScript

Your options attribute:

JavaScript

Pass them to the Bar:

JavaScript

Your chart:

enter image description here

Learn more and see more examples in the docs.

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement