react-chartjs-2

React components for Chart.js — typed, hooks-friendly charts for React apps

Library
npm
v5.3.1
6,942stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
69/100Good
Development Activity52
Maintenance48
Community76
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
85/100Excellent
Architecture85
Code Quality78
Innovation88
Learning Curve90

react-chartjs-2 wraps Chart.js in a small set of idiomatic React components so you can render line, bar, pie, doughnut, radar, and other chart types declaratively instead of imperatively managing a canvas instance yourself. It exposes both a generic Chart component and pre-typed shortcuts like Line, Bar, and Doughnut, each forwarding a ref to the underlying Chart.js instance for cases where you need direct imperative access (e.g. programmatic zoom or tooltip control). Under the hood it reconciles React’s declarative re-renders with Chart.js’s stateful, canvas-based rendering model using effect hooks, so passing new data or options props updates the existing chart in place instead of tearing down and rebuilding the canvas on every render.

It supports Chart.js v3 and v4, ships full TypeScript typings that propagate chart type, data point, and label generics through props, and has no runtime dependencies beyond chart.js and react as peer dependencies — keeping bundle size close to whatever Chart.js modules you register yourself.

What You Get

  • A generic Chart component plus pre-typed shortcuts (Line, Bar, Doughnut, Pie, Radar, PolarArea, Bubble, Scatter) that auto-register the matching Chart.js controller
  • Ref forwarding to the underlying Chart.js instance for imperative access (manual update(), plugin APIs, programmatic zoom)
  • In-place chart updates on prop changes (labels, datasets, options) instead of destroy-and-recreate on every render, using a dataset-id-aware diffing utility
  • Full TypeScript generics that carry chart type, data point shape, and label type through props for compile-time-checked chart configuration
  • Helper functions (getDatasetAtEvent, getElementAtEvent, getElementsAtEvent) for mapping canvas mouse events back to Chart.js dataset/element hits
  • Support for both Chart.js v3 and v4 with dedicated migration guides

Common Use Cases

  • Dropping a dashboard chart (line, bar, pie) into a React admin panel or analytics UI without hand-rolling canvas lifecycle management
  • Building interactive charts that respond to click/hover events by mapping canvas coordinates back to specific datasets or data points
  • Rendering charts whose data updates frequently (e.g. live metrics) where in-place updates avoid the flicker and cost of full chart teardown
  • Combining Chart.js plugins (zoom, annotation, date adapters) with a typed React wrapper instead of manipulating the Chart.js instance directly

Under The Hood

Architecture — The library’s entire runtime surface is four small files under src/: chart.tsx holds the core ChartComponent, which owns a canvasRef/chartRef pair and a cascade of useEffect hooks that translate prop changes (options, data.labels, data.datasets, type) into imperative Chart.js calls (chart.update(), or a full destroy/recreate via setTimeout(renderChart) when type or redraw changes) rather than re-instantiating a ChartJS object on every React render. typedCharts.tsx builds the named exports (Line, Bar, Doughnut, etc.) by calling ChartJS.register() with the matching controller and wrapping Chart in a forwardRef closure, so each named component is really the same ChartComponent pre-bound to a type and its required controller. utils.ts contains the dataset-reconciliation logic (setDatasets, cloneData) that matches incoming datasets to existing ones by a configurable datasetIdKey (default label) so in-place updates preserve Chart.js’s internal per-dataset animation/meta state instead of discarding it.

Tech Stack — Written in TypeScript against React’s forwardRef/hooks API with chart.js (^4.1.1) and react (^16.8.0 through ^19) as peer dependencies only — no other runtime dependencies. Built with Rollup (rollup.config.js) plus a separate tsc --emitDeclarationOnly pass for .d.ts output, and developed against Vite/Vitest tooling (vite.config.js) with Storybook 8 for the component playground published at website/.

Code Qualitytest/chart.test.tsx (433 lines) covers rendering, ref forwarding, redraw behavior, and dataset/label update paths using @testing-library/react and vitest-canvas-mock to stub the canvas API; test/chart.test-d.tsx runs tsd type-level assertions to guard the exported generics. Source files are consistently typed (no any in the public surface), utility functions carry JSDoc comments, and ESLint (eslint-config-standard + React/Prettier plugins) plus a simple-git-hooks/nano-staged pre-commit setup enforce lint-clean, formatted commits. No integration tests against a real browser/canvas exist — all canvas interaction is mocked.

API Design — The public API is deliberately minimal: <Doughnut data={...} /> is a complete, working chart with no required boilerplate beyond passing data. Named chart components remove the need to manually call ChartJS.register() for common cases, while the generic Chart component and full TypeScript generics (ChartProps<TType, TData, TLabel>) are available when more control or an uncommon chart type is needed. The one piece of friction the docs call out repeatedly (via dedicated FAQ/migration pages) is that Chart.js v4’s tree-shakeable module registration model still leaks through for anything outside the pre-typed helpers, so consumers of less common configurations must understand Chart.js’s own controller/element/plugin registration to use the generic Chart component correctly.

Used by 19 apps in this directory

Python
90%
Apache 2.0

Apache Airflow

Data Engineering

46,530

Define, schedule, and monitor complex data workflows as Python code — with a powerful UI, 80+ provider integrations, and battle-tested scalability across thousands of production deployments.

View details
96
Repo Health
89
Technical
66
Dependency
Built with
Python90%
Updated today
TypeScript
51%
MIT

Anarlog

Note Taking · AI Assistants · Productivity

9,087

Anarlog is an open-source, local-first AI meeting notetaker that records, transcribes, and summarizes meetings entirely on your device — no cloud lock-in, no mandatory account, and every note saved as a plain markdown file you own forever.

View details
86
Repo Health
77
Technical
69
Dependency
Built with
TypeScript51%
Rust38%
Updated today
Go
85%
Apache 2.0

Argo Workflows

Devops · Data Engineering

16,916

The most popular Kubernetes-native workflow engine for orchestrating containerized DAGs, ML pipelines, CI/CD, and parallel batch jobs at scale.

View details
96
Repo Health
90
Technical
70
Dependency
Built with
Go85%
TypeScript11%
Updated today
Go
55%
Apache 2.0

Authgear

Authentication

1,989

Open-source, self-hostable authentication platform with passkeys, biometric login, SSO, MFA, and GraphQL admin API — a full Auth0/Clerk/Firebase alternative for SaaS and mobile apps.

View details
88
Repo Health
81
Technical
72
Dependency
Built with
Go55%
HTML26%
TypeScript17%
Updated yesterday
JavaScript
99%
Other

ChartBrew

Analytics · Databases

4,041

Open-source reporting platform to build live dashboards from SQL, NoSQL, APIs, and SaaS tools with an AI assistant that creates charts from natural language.

View details
90
Repo Health
83
Technical
65
Dependency
Built with
JavaScript99%
Updated 6 days ago
TypeScript
93%
AGPL 3.0

CourseLit

Ecommerce · Blogging

1,255

Open-source, self-hosted LMS for selling online courses, digital downloads, and building communities on your own branded website.

View details
78
Repo Health
74
Technical
72
Dependency
Built with
TypeScript93%
Updated 4 weeks ago
Go
73%
Other

Flipt

Devops · Developer Tools

4,872

Git-native feature flag platform that stores, versions, and deploys feature toggles directly in your own Git repositories with no external database required.

View details
90
Repo Health
83
Technical
70
Dependency
Built with
Go73%
TypeScript26%
Updated today
TypeScript
100%
Apache 2.0

ILLA Builder

Developer Tools · Low Code Platforms · No Code Platforms

12,311

Open-source low-code platform for building internal tools with drag-and-drop UI, reactive data bindings, and real-time collaboration.

View details
58
Repo Health
71
Technical
65
Dependency
Built with
TypeScript100%
Updated 2 months ago
Python
63%
Other

Keep

Devops · Automation · Monitoring

12,224

The open-source AIOps and alert management platform that unifies 130+ monitoring tools into a single pane of glass with AI-powered correlation, deduplication, and workflow automation.

View details
91
Repo Health
79
Technical
67
Dependency
Built with
Python63%
TypeScript36%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search