![]() |
VOOZH | about |
Rechart JS is a library that is used for creating charts for React JS. This library is used for building Line charts, Bar charts, Pie charts, etc, with the help of React and D3 (Data-Driven Documents). In this article, we will learn how to Create a Brush Bar Chart using Recharts in ReactJS.
We create a normal bar chart using BarChart and Bar component of recharts npm package. To convert it to Brush bar chart we add Brush component to BarChart component.
Step 1: Create a React application using the following command.
npx create-react-app foldernameStep 2: After creating your project folder i.e. foldername, move to it using the following command.
cd foldernameStep 3: After creating the ReactJS application, Install the required modules using the following command.
npm install --save rechartsProject Structure:
👁 ImageExample 1: In this example, we will create a basic bar chart using BarChart component. To convert it to Brushed chart we will add Brush Component inside BarChart component.
Step to Run Application: Run the application using the following command from the root directory of the project:
npm start
Output: Now open your browser and go to http://localhost:3000/, you will see the following output:
Example 2: In this example, in order to add more categories of data, we will add more Bar components and add a Tooltip that shows data related to the bar on hover using the Tooltip component of recharts npm package. We can even use negative values and make reference lines using the Reference line component of recharts npm package.
Output: Save the file using CTRL+S. Now open your browser and go to http://localhost:3000/, you will see the following