Recharts

A composable charting library built on React components

 Install v3.10.1
import { CartesianGrid, Legend, Line, LineChart, XAxis, YAxis } from 'recharts';
import { RechartsDevtools } from '@recharts/devtools';

// #region Sample data
const data = [
  {
    name: 'A',
    uv: 400,
    pv: 240,
    amt: 2400,
  },
  {
    name: 'B',
    uv: 300,
    pv: 456,
    amt: 2400,
  },
  {
    name: 'C',
    uv: 300,
    pv: 139,
    amt: 2400,
  },
  {
    name: 'D',
    uv: 200,
    pv: 980,
    amt: 2400,
  },
  {
    name: 'E',
    uv: 278,
    pv: 390,
    amt: 2400,
  },
  {
    name: 'F',
    uv: 189,
    pv: 480,
    amt: 2400,
  },
];

// #endregion

export default function IndexLineChart() {
  return (
    <LineChart style={{ width: '100%', aspectRatio: 1.618, maxWidth: 800, margin: 'auto' }} responsive data={data}>
      <CartesianGrid strokeDasharray="5 5" />
      <XAxis dataKey="name" />
      <YAxis width="auto" />
      <Line type="monotone" dataKey="uv" />
      <Line type="monotone" dataKey="pv" />
      <Legend position="insideTopRight" offset={20} />
      <RechartsDevtools />
    </LineChart>
  );
}

Features

  • Composable

    Quickly build your charts with decoupled, reusable React components.

  • Reliable

    Built on top of SVG elements with a lightweight dependency on D3 submodules.

  • Powerful

    Customize your chart by tweaking component props and passing in custom components.

Thanks to our sponsors

Browser testing via TestMu AI