React Js Google Column Chart Example

In this tutorial, you will learn how to create column charts in react js application using google charts apis.

How to Create and Use Google Column Charts in React Js

Steps to create column chart using google charts apis:

Step 1 – Create React App

If you don’t have a React application set up in your system, run the following commands to create a new React app:

npx create-react-app my-react-app

To run the React app:

npm start

Check out your React app on this URL: localhost:3000

Step 2 – Install and Set Up react-google-charts

Run the following command to install Google Charts library:

npm install bootstrap

# npm
npm install react-google-charts

# yarn
yarn add react-google-charts

Step 3 – Create Google Column Charts Component

Create column chart component named GoogleChart.js in src directory, and then add google charts js library to implement column chart in it:

import React, { Component } from "react";
import Chart from "react-google-charts";
const data = [
['Year', 'Visitations', { role: 'style' } ],
['2010', 10, 'color: gray'],
['2020', 14, 'color: #76A7FA'],
['2030', 16, 'opacity: 0.2'],
['2040', 22, 'stroke-color: #703593; stroke-width: 4; fill-color: #C5A5CF'],
['2050', 28, 'stroke-color: #871B47; stroke-opacity: 0.6; stroke-width: 8; fill-color: #BC5679; fill-opacity: 0.2']
];
class GoogleChart extends Component {

constructor(props) {
super(props)
}
render() {
return (
<div className="container mt-5">
<h2>Google Column Chart in React Js</h2>
<Chart
width={700}
height={320}
data={data}
chartType="ColumnChart"
loader={<div>Loading Chart...</div>}
/>
</div>
)
}
}
export default GoogleChart;

Step 4 – Import Component in App.js

In this step, you need to import GoogleChart.js file in src/App.js file:

import React from 'react';
import '../node_modules/bootstrap/dist/css/bootstrap.min.css';
import GoogleChart from './components/GoogleChart';
function App() {
return (
<div className="App">
<GoogleChart />
</div>
);
}
export default App;

Now you can run this application and test it on browser.

Conclusion

That’s it, you have learned how to install react google chats in react app and how to create google column charts component in react js app.

Recommended React JS Tutorials

AuthorDevendra Dode

Greetings, I'm Devendra Dode, a full-stack developer, entrepreneur, and the proud owner of Tutsmake.com. My passion lies in crafting informative tutorials and offering valuable tips to assist fellow developers on their coding journey. Within my content, I cover a spectrum of technologies, including PHP, Python, JavaScript, jQuery, Laravel, Livewire, CodeIgniter, Node.js, Express.js, Vue.js, Angular.js, React.js, MySQL, MongoDB, REST APIs, Windows, XAMPP, Linux, Ubuntu, Amazon AWS, Composer, SEO, WordPress, SSL, and Bootstrap. Whether you're starting out or looking for advanced examples, I provide step-by-step guides and practical demonstrations to make your learning experience seamless. Let's explore the diverse realms of coding together.

Leave a Reply

Your email address will not be published. Required fields are marked *