React Chart.js 2
React components wrapper for Chart.js enabling data visualization with charts.
3. Used by agents' projects
Dependency in 41 public GitHub projects set up for AI coding agents that we scanned (0.7%).
4. Agent access
Agent skills for this library in the skills catalog; community skills are written by others, read them before you install.
From the package registry and GitHub, checked daily. Tap a verdict to see its source.How we checkedReport an error
What React Chart.js 2 does
react-chartjs-2 is a thin layer of React components over Chart.js. You choose and register the Chart.js parts your charts need, and typed components such as <code>Line</code> or <code>Doughnut</code> register their own controller.
React Chart.js 2 popularity
Gid Score measures public popularity and activity, not quality. How the Gid Score is calculated
How React Chart.js 2 is used
- React Chart.js 2 is a dependency in 41 of the 6,258 public GitHub projects set up for AI coding agents that we scanned (0.8% of the 4,867 JavaScript/TypeScript ones), #8 of 95 in charts and data visualisation.
- Counting the projects our scan samples by dependency (Solana 3,067, Ethereum and EVM 1,774, 3D and games 3,130, agent frameworks and SDKs 13,750), it appears in 158; those are left out of every share on this page.
- The most used alternative in our scan is Recharts (576 projects).
- Projects that use it most often also use Chart.js (97.6%), Lucide React (85.4%), React (100.0%).
By coding agent
Often used with
React Chart.js 2 in practice
Strengths
The docs describe a "lazy way", <code>import 'chart.js/auto'</code>, and a tree-shakable way where you register only the parts you use. The maintainers recommend the second to keep the bundle smaller.
With a component like <code>Line</code>, you do not register <code>LineController</code> yourself. You register only the elements, scales and plugins.
The site says both major Chart.js versions are supported and links a separate guide for v3.
A <code>ref</code> on the component gives you the Chart.js chart. The docs' gradient example reads <code>chart.ctx</code> from <code>chartRef.current</code> to build a background gradient.
Watch out for
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.
You add <code>chart.js</code> alongside <code>react-chartjs-2</code>. The README recommends a specific major version of Chart.js.
Imports like <code>defaults</code> and the Chart.js <code>Chart</code> class now come from <code>chart.js</code>, not from this package. The old default export became the named <code>Chart</code> component.
Line component with tree-shaken registration
import { Line } from 'react-chartjs-2' ;
import { Chart as ChartJS , LineElement , PointElement , LinearScale , Title } from 'chart.js' ;
ChartJS . register ( LineElement , PointElement , LinearScale , Title ) ;
< Line data = { chartData } />More about React Chart.js 2
Packages around it
- chart.js: Charting engine (peer dependency)
- framer-motion: Animation
- react: UI library
- lucide-react: Icons
- react-router-dom: Routing
- date-fns: Date utilities
More in Charts and data visualisation
Alternatives
React Chart.js 2 This page
Composable React component library for building responsive charts.
JavaScript library for creating data-driven documents with powerful data visualization capabilities.
React wrapper for ApexCharts with server-side rendering support.
Get started
Install it.
npm install react-chartjs-2Rules for your agent
## 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.