AG Charts React Component

13.2.1 · active · verified Sun Apr 19

AG Charts React is a high-performance, canvas-based charting library for React applications. It offers a comprehensive set of 30+ chart types, including common visualizations like bar, line, area, and pie charts, as well as specialized types such as financial charts and maps (some advanced features are part of the Enterprise version). The library prioritizes outstanding performance, especially with large datasets and high-frequency updates, and boasts no third-party runtime dependencies, minimizing bundle size and potential conflicts. The current stable version is 13.2.1, with frequent patch and minor releases, and major versions typically introducing significant API or feature enhancements. Key differentiators include its performance, native React integration, comprehensive feature set (split between Community and Enterprise), and a focus on enterprise application development.

Common errors

Warnings

Install

Imports

Quickstart

Initializes and renders a combination bar and line chart using `AgChartsReact`. It demonstrates defining data, multiple series, dual axes, basic styling, and accessing the chart instance via a ref.

import React, { useState, useRef, useEffect } from 'react';
import { AgChartsReact } from 'ag-charts-react';
import type { AgChartOptions, AgChartInstance } from 'ag-charts-react';

const ChartExample: React.FC = () => {
  const chartRef = useRef<AgChartInstance | null>(null);
  const [options, setOptions] = useState<AgChartOptions>({
    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: [
      {
        type: 'bar',
        xKey: 'month',
        yKey: 'iceCreamSales',
        yName: 'Ice Cream Sales',
      },
      {
        type: 'line',
        xKey: 'month',
        yKey: 'avgTemp',
        yName: 'Average Temperature',
        marker: { enabled: true },
        strokeWidth: 3,
        axes: 'secondary-y-axis',
      },
    ],
    axes: [
      { type: 'category', position: 'bottom' },
      { type: 'number', position: 'left', title: { text: 'Sales' } },
      {
        type: 'number',
        position: 'right',
        id: 'secondary-y-axis',
        title: { text: 'Temperature (°C)' },
      },
    ],
    title: { text: 'Ice Cream Sales vs. Average Temperature' },
    subtitle: { text: '(Monthly Data)' },
    legend: { enabled: true },
  });

  useEffect(() => {
    // Example of programmatic API interaction after mount
    if (chartRef.current) {
      console.log('Chart instance available:', chartRef.current);
      // You could call chartRef.current.download('my-chart.png') here for example
    }
  }, []);

  return (
    <div style={{ height: '500px', width: '100%' }}>
      <AgChartsReact ref={chartRef} options={options} />
    </div>
  );
};

export default ChartExample;

view raw JSON →