Convert Figma logo to code with AI

rakannimer logoreact-google-charts

A thin, typed, React wrapper over Google Charts Visualization and Charts API.

1,593
345
1,593
144

Top Related Projects

23,884

Redefined chart library built with React and D3

📊 React Component for ApexCharts

13,142

nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries

10,987

A collection of composable React components for building interactive data visualizations

React components for Chart.js, the most popular charting library

Data Visualization Components

Quick Overview

The react-google-charts library is a React wrapper for the Google Charts API, allowing developers to easily integrate interactive data visualization charts into their React applications.

Pros

  • Comprehensive Charting Options: The library provides a wide range of chart types, including line charts, bar charts, pie charts, scatter plots, and more, allowing developers to choose the most appropriate visualization for their data.
  • Easy Integration: The library abstracts away the complexity of the Google Charts API, making it easy for React developers to integrate charts into their applications with minimal setup.
  • Customization: The library offers extensive customization options, allowing developers to fine-tune the appearance and behavior of the charts to match their application's design and requirements.
  • Active Development: The project is actively maintained, with regular updates and bug fixes, ensuring that developers can rely on the library's stability and compatibility with the latest versions of React.

Cons

  • Dependency on Google Charts API: The library is dependent on the Google Charts API, which may not be suitable for all use cases or projects that prefer to use alternative charting libraries.
  • Limited Functionality: While the library provides a wide range of chart types, it may not offer the same level of advanced functionality and customization as some other charting libraries.
  • Performance Concerns: Depending on the complexity and size of the data being visualized, the library may have performance implications, especially for large datasets or complex chart types.
  • Learning Curve: Developers who are new to the Google Charts API may need to invest time in understanding the library's API and how to effectively use it within their React applications.

Code Examples

Rendering a Line Chart

import React from 'react';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'react-google-charts';

const LineChartExample = () => {
  const data = [
    ['Year', 'Sales', 'Expenses'],
    ['2016', 1000, 400],
    ['2017', 1170, 460],
    ['2018', 660, 1120],
    ['2019', 1030, 540],
  ];

  const options = {
    title: 'Company Performance',
    curveType: 'function',
    legend: { position: 'bottom' },
  };

  return (
    <LineChart
      width={600}
      height={400}
      data={data}
      options={options}
    />
  );
};

export default LineChartExample;

Rendering a Pie Chart

import React from 'react';
import { PieChart, Pie, Sector, Cell } from 'react-google-charts';

const PieChartExample = () => {
  const data = [
    ['Task', 'Hours per Day'],
    ['Work', 11],
    ['Eat', 2],
    ['Commute', 2],
    ['Watch TV', 2],
    ['Sleep', 7],
  ];

  const options = {
    title: 'My Daily Activities',
  };

  return (
    <PieChart width={400} height={400}>
      <Pie
        data={data}
        cx={200}
        cy={200}
        labelLine={false}
        outerRadius={80}
        fill="#8884d8"
        dataKey="value"
      >
        {data.map((entry, index) => (
          <Cell key={`cell-${index}`} fill={COLORS[index % COLORS.length]} />
        ))}
      </Pie>
    </PieChart>
  );
};

export default PieChartExample;

Getting Started

To get started with react-google-charts, follow these steps:

  1. Install the library using npm or yarn:
npm install react-google-charts
# or
yarn add react-google-charts
  1. Import the necessary components from the library and use them in your React component:
import React from 'react';
import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'react-google-charts';

const MyChart = () => {

Competitor Comparisons

23,884

Redefined chart library built with React and D3

Pros of Recharts

  • Built specifically for React, offering better integration and performance
  • Highly customizable with a wide range of chart types
  • Smaller bundle size, leading to faster load times

Cons of Recharts

  • Less extensive documentation compared to Google Charts
  • Fewer advanced features and chart types available
  • May require more custom coding for complex visualizations

Code Comparison

Recharts:

import { LineChart, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend } from 'recharts';

<LineChart width={600} height={300} data={data}>
  <Line type="monotone" dataKey="value" stroke="#8884d8" />
  <CartesianGrid stroke="#ccc" />
  <XAxis dataKey="name" />
  <YAxis />
</LineChart>

React Google Charts:

import { Chart } from "react-google-charts";

<Chart
  width={'600px'}
  height={'300px'}
  chartType="LineChart"
  loader={<div>Loading Chart</div>}
  data={[["Name", "Value"], ...data]}
  options={{
    hAxis: { title: 'Name' },
    vAxis: { title: 'Value' },
  }}
/>

Both libraries offer straightforward ways to create charts, but Recharts provides a more React-like component structure, while React Google Charts relies more on configuration objects.

📊 React Component for ApexCharts

Pros of react-apexcharts

  • More customizable and feature-rich, offering a wider range of chart types and options
  • Better performance, especially for large datasets and real-time updates
  • Smaller bundle size, leading to faster load times

Cons of react-apexcharts

  • Less familiar to developers who are used to Google Charts
  • May require more configuration and setup for basic charts
  • Limited integration with Google ecosystem (e.g., Google Sheets)

Code Comparison

react-google-charts:

import { Chart } from "react-google-charts";

<Chart
  chartType="LineChart"
  data={[["Year", "Sales"], [2004, 1000], [2005, 1170], [2006, 660]]}
  width="100%"
  height="400px"
/>

react-apexcharts:

import Chart from "react-apexcharts";

<Chart
  options={{
    chart: { type: "line" },
    xaxis: { categories: [2004, 2005, 2006] }
  }}
  series={[{ name: "Sales", data: [1000, 1170, 660] }]}
  width="100%"
  height={400}
/>

Both libraries offer React components for creating charts, but react-apexcharts provides more granular control over chart options and data structure. react-google-charts uses a simpler data array format, while react-apexcharts separates options and series data for more flexibility.

13,142

nivo provides a rich set of dataviz components, built on top of the awesome d3 and React libraries

Pros of nivo

  • Highly customizable with a wide range of chart types and options
  • Built with React and D3, offering smooth animations and interactions
  • Provides server-side rendering capabilities for improved performance

Cons of nivo

  • Steeper learning curve due to its extensive API and configuration options
  • Larger bundle size compared to react-google-charts

Code Comparison

nivo:

import { ResponsivePie } from '@nivo/pie'

const MyPieChart = ({ data }) => (
  <ResponsivePie
    data={data}
    margin={{ top: 40, right: 80, bottom: 80, left: 80 }}
    innerRadius={0.5}
    padAngle={0.7}
    cornerRadius={3}
  />
)

react-google-charts:

import { Chart } from "react-google-charts"

const MyPieChart = ({ data }) => (
  <Chart
    chartType="PieChart"
    data={data}
    options={{
      title: "My Pie Chart",
      is3D: true,
    }}
    width={"100%"}
    height={"400px"}
  />
)

Both libraries offer React components for creating charts, but nivo provides more granular control over chart appearance and behavior. react-google-charts relies on Google Charts API, which may be more familiar to some developers and offers a simpler API for basic use cases.

10,987

A collection of composable React components for building interactive data visualizations

Pros of Victory

  • Fully customizable and flexible charting library
  • Supports animations and interactive elements out-of-the-box
  • Smaller bundle size, potentially better performance

Cons of Victory

  • Steeper learning curve due to its flexibility
  • Less variety of chart types compared to react-google-charts
  • May require more code to achieve complex visualizations

Code Comparison

Victory:

import { VictoryBar, VictoryChart, VictoryAxis } from 'victory';

<VictoryChart>
  <VictoryAxis tickValues={[1, 2, 3, 4]} />
  <VictoryAxis dependentAxis />
  <VictoryBar data={data} x="quarter" y="earnings" />
</VictoryChart>

react-google-charts:

import { Chart } from 'react-google-charts';

<Chart
  chartType="BarChart"
  data={[['Quarter', 'Earnings'], ...data]}
  options={{ title: 'Earnings by Quarter' }}
  width="100%"
  height="400px"
/>

Victory offers more granular control over chart elements, while react-google-charts provides a simpler API for quick implementation. Victory's approach allows for more customization but may require more code for basic charts. react-google-charts leverages Google's charting library, offering a wide range of pre-built chart types with less customization overhead.

React components for Chart.js, the most popular charting library

Pros of react-chartjs-2

  • Lightweight and fast rendering due to Chart.js dependency
  • Extensive customization options and plugin support
  • Active community and frequent updates

Cons of react-chartjs-2

  • Limited chart types compared to Google Charts
  • Less integration with Google ecosystem (e.g., Google Sheets)
  • Steeper learning curve for complex visualizations

Code Comparison

react-chartjs-2:

import { Line } from 'react-chartjs-2';

const data = {
  labels: ['Jan', 'Feb', 'Mar'],
  datasets: [{ data: [3, 6, 9] }]
};

<Line data={data} />

react-google-charts:

import { Chart } from 'react-google-charts';

const data = [
  ['Month', 'Sales'],
  ['Jan', 3],
  ['Feb', 6],
  ['Mar', 9]
];

<Chart chartType="LineChart" data={data} />

Both libraries offer simple ways to create charts, but react-chartjs-2 uses a more React-like approach with separate data and options objects, while react-google-charts follows Google Charts' data format more closely.

Data Visualization Components

Pros of react-vis

  • Fully customizable and flexible, allowing for more complex and unique visualizations
  • Lightweight and fast, with a smaller bundle size
  • Built specifically for React, offering better integration with React applications

Cons of react-vis

  • Less extensive documentation compared to react-google-charts
  • Smaller community and fewer examples available
  • May require more coding effort for basic charts

Code Comparison

react-google-charts:

import { Chart } from "react-google-charts";

<Chart
  chartType="LineChart"
  data={[["Year", "Sales"], [2004, 1000], [2005, 1170], [2006, 660]]}
  width="100%"
  height="400px"
/>

react-vis:

import { XYPlot, LineSeries, XAxis, YAxis } from "react-vis";

<XYPlot width={300} height={300}>
  <LineSeries data={[{x: 1, y: 10}, {x: 2, y: 5}, {x: 3, y: 15}]} />
  <XAxis />
  <YAxis />
</XYPlot>

Both libraries offer ways to create charts in React applications, but react-google-charts provides a more straightforward approach for common chart types, while react-vis offers greater flexibility and customization options. react-google-charts leverages Google's charting library, which may be familiar to some developers, while react-vis is built from the ground up for React, potentially offering better performance and integration in React applications.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

React Google Charts

Logo

A thin, typed, React wrapper for Google Charts.

version downloads license bundle size


Quickstart   â€¢   Docs   â€¢   Contributing   â€¢   Stack Overflow

Quickstart

Install this library with your favorite package manager:

yarn add react-google-charts

or

npm install --save react-google-charts

Then, import and use it:

import { Chart } from "react-google-charts";

<Chart
  chartType="ScatterChart"
  data={[["Age", "Weight"], [4, 5.5], [8, 12]]}
  width="100%"
  height="400px"
  legendToggle
/>

Docs

You can also check this step-by-step tutorial that will walk you through the creation of a full-fledged dashboard with this library.

Contributing

Contributions are very welcome. Check out CONTRIBUTING.md

Run the Storybook

git clone https://www.github.com/rakannimer/react-google-charts
cd react-google-charts
yarn
yarn start:storybook

NPM DownloadsLast 30 Days