# React Chart.js 2 — card for AI agents

React components wrapper for Chart.js enabling data visualization with charts.

Category: Charts and data visualisation · npm package `react-chartjs-2` · latest version 5.3.1 (checked 2026-11-01)
Install: `npm install react-chartjs-2`
License: MIT (permissive)

In your own product (generator, app, hosted service): **yes**. Permissive license: ship it inside your own product, closed or open source, and keep its license and copyright notice.

## Rules for AI agents (paste into AGENTS.md or CLAUDE.md)

## react-chartjs-2
- Install both packages: `react-chartjs-2` and `chart.js`. The README recommends `chart.js@^4.0.0`.
- Before rendering, register the Chart.js elements, scales and plugins a chart needs with `ChartJS.register(...)`. Typed components like `Line` already register their controller.
- Prefer tree-shakable registration over `import 'chart.js/auto'`. The docs call the auto import the "lazy way".
- Import `Chart as ChartJS`, `defaults` and the elements from `chart.js`. This package no longer re-exports them.
- For click data, attach a `ref` and call `getDatasetAtEvent`, `getElementAtEvent` or `getElementsAtEvent` with `chartRef.current` and the event inside `onClick`.
- Do not pass a function to `data`. For gradients, read `chart.ctx` from a ref in `useEffect` and set the data with state.

## What it is
- react-chartjs-2 provides "React components for Chart.js". It is published on npm as `react-chartjs-2` under the MIT license. The GitHub repository was created on 2016-05-06, and the latest listed release is v5.3.1, published 2025-10-27. The site says it supports Chart.js v4 and Chart.js v3.
- Chart.js is a peer dependency, so you install both packages. You import an individual component such as `Doughnut` and pass it a `data` prop. The docs say the library is tree-shakable, just like Chart.js v3. That means you import and register the controllers, elements, scales and plugins your charts use.
- It is for React developers who want Chart.js charts written as JSX components. You handle Chart.js registration yourself. When you need things like gradients or click data, you also work with the Chart.js instance through a ref.

## Caveats
- Registration errors are a known question: The FAQ lists entries on fixing "not a registered element" and "not a registered scale" errors. It also lists questions about charts that do not keep their width or height, and background fills that do not work.
- Chart.js is a separate install: You add `chart.js` alongside `react-chartjs-2`. The README recommends a specific major version of Chart.js.
- v4 removed the chart.js re-exports: Imports like `defaults` and the Chart.js `Chart` class now come from `chart.js`, not from this package. The old default export became the named `Chart` component.
- Gradients need a ref, an effect and state: You can no longer pass a function as `data` to reach the canvas. The docs' v4 version uses `useRef`, `useEffect` and `useState` instead.

## Numbers (AgentGid data)
- Gid Score: 63.5 (#763 of all tools, 11 of 95 in its category)
- Used in 41 public projects set up for AI coding agents (0.7%)
- Downloads last week: 6,195,944 (as of 2026-11-24), +31.9% over 4 weeks
- GitHub stars: 6,939 (as of 2026-11-24)
- Last push: 2026-11-20

## Often used with
Chart.js 97.6%, Lucide React 85.4%, React 100.0%, clsx 73.2%, Radix UI 65.9%, Class Variance Authority 65.9%

## Checked alternatives (same job)
- Recharts: https://agentgid.com/tools/recharts/agent.md
- D3.js: https://agentgid.com/tools/d3/agent.md
- React ApexCharts: https://agentgid.com/tools/react-apexcharts/agent.md

## Links
- AgentGid page: https://agentgid.com/tools/react-chartjs-2/
- Homepage: https://github.com/reactchartjs/react-chartjs-2
- Repository: https://github.com/reactchartjs/react-chartjs-2
- Source: https://github.com/reactchartjs/react-chartjs-2#readme
- Source: https://github.com/reactchartjs/react-chartjs-2
- Source: https://github.com/reactchartjs/react-chartjs-2/releases
- Source: https://react-chartjs-2.js.org
- Source: https://react-chartjs-2.js.org/docs/migration-to-v4
- Source: https://react-chartjs-2.js.org/faq

---
AgentGid's catalog is curated: every entry was checked against the maker's official pages (registry, repository, license and pricing pages) on the date shown; a license value shows the quote it stands on wherever AgentGid has one. Usage numbers come from AgentGid's own scan of public repositories set up for AI coding agents. Claims by makers are reported, not tested by AgentGid.
