Chart.js is a free, open-source JavaScript library for data visualization. Its one of the most popular yet simplest visualization libraries in JavaScript.
Chart.js is written in JavaScript, therefore it is easy to use it in plain JavaScript. However it is a pain to integrate it with React Js. For that purpose we will use another wrapper library react-chart-js-2. In this post we will integrate it React Typescript project.
Follow these steps
Install the required packages
Declare chart data
In this case we will use the bar chart as an example. Go to the component to which you want to integrate the chart. Let us set the data that will be used by the chart in React state.
Use the Chart Element
Time to add the chart element in the component template.
At this point if you try to refresh the browser you will see that the Chart will not render. Instead you will see some error messages in the browser console stating that some chart elements are not registered.
This is because Chart.js 3 is tree-shakeable, so it is necessary to import and register the controllers, elements, scales and plugins you are going to use.
Register the Chart Elements
The elements that you will need to register will depend on the Chart type that you are using. In case of the Bar Chart we will need to register the following elements.
To learn more about all available elements see Chart.js documentation.
Now if you reload the page again you should see the Chart rendered correctly.

Here is the full component code
Updating the Chart with new Data
The Chart will re-render automatically whenever the data is changed using setData