React ChartsQuick Start

Add React Charts and React Graphs to your application in 60 seconds.

Install

Install the AG Charts React library:

npm install ag-charts-react
yarn add ag-charts-react

Create a React Chart

Replace your index.js file (or root component) with the following code:

import React, { useState } from 'react';
import ReactDOM from 'react-dom/client';
import { AgCharts } from 'ag-charts-react';

// React Chart Component
const ChartExample = () => {
  // Chart Options: Control & configure the chart
  const [chartOptions, setChartOptions] = useState({
    // Data: Data to be displayed in the chart
    data: [
        { month: 'Jan', avgTemp: 2.3, iceCreamSales: 162000 },
        { month: 'Mar', avgTemp: 6.3, iceCreamSales: 302000 },
        { month: 'May', avgTemp: 16.2, iceCreamSales: 800000 },
        { month: 'Jul', avgTemp: 22.8, iceCreamSales: 1254000 },
        { month: 'Sep', avgTemp: 14.5, iceCreamSales: 950000 },
        { month: 'Nov', avgTemp: 8.9, iceCreamSales: 200000 },
    ],
    // Series: Defines which chart type and data to use
    series: [{ type: 'bar', xKey: 'month', yKey: 'iceCreamSales' }],
  });

  return (
    // AgCharts component with options passed as prop
    <AgCharts options={chartOptions} />
  );
}

// Render component inside root element
const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(<ChartExample />);

Example Chart

When you run your app, you should see a very simple React chart:

Next Steps