highcharts-react-official、react-chartjs-2、react-highcharts、recharts は、React アプリケーションでデータ可視化を実現するための主要なライブラリです。それぞれが異なるレンダリングエンジン(SVG または Canvas)と、React との統合アプローチ(ラッパーまたはネイティブコンポーネント)を採用しており、プロジェクトの要件に応じて適切な選択が必要です。
React エコシステムには多くの图表ライブラリが存在しますが、highcharts-react-official、react-chartjs-2、react-highcharts、recharts は特に注目すべき 4 つです。これらはそれぞれ異なる哲学を持っており、単に「グラフを描く」だけでなく、アプリケーションのパフォーマンス、メンテナンス性、ライセンスコストに直接影響します。
recharts は SVG を使用します。
// recharts: SVG based
import { LineChart, Line } from 'recharts';
<LineChart width={500} height={300} data={data}>
<Line dataKey="value" stroke="#8884d8" />
</LineChart>
react-chartjs-2 は Canvas を使用します。
<canvas> 要素に描画するため、DOM ノード数が少なく、大量データでも比較的高速です。// react-chartjs-2: Canvas based
import { Line } from 'react-chartjs-2';
<Line data={chartData} options={chartOptions} />
highcharts-react-official は SVG を使用します。
// highcharts-react-official: SVG based
import HighchartsReact from 'highcharts-react-official';
<HighchartsReact highcharts={Highcharts} options={chartOptions} />
react-highcharts も SVG を使用します。
// react-highcharts: SVG based (Legacy)
import ReactHighcharts from 'react-highcharts';
<ReactHighcharts config={chartConfig} />
recharts は React コンポーネントとして設計されています。
// recharts: Declarative Components
<BarChart data={data}>
<XAxis dataKey="name" />
<Bar dataKey="uv" fill="#8884d8" />
</BarChart>
react-chartjs-2 は Chart.js のラッパーです。
// react-chartjs-2: Configuration Object
const options = { responsive: true };
<Line options={options} data={data} />
highcharts-react-official もラッパーアプローチです。
// highcharts-react-official: Configuration Object
const options = { chart: { type: 'line' } };
<HighchartsReact options={options} />
react-highcharts は古いラッパーです。
// react-highcharts: Configuration Object
const config = { chart: { type: 'line' } };
<ReactHighcharts config={config} />
highcharts-react-official は公式サポートがあります。
// highcharts-react-official: Licensed
// Requires commercial license for non-personal use
import HighchartsReact from 'highcharts-react-official';
react-highcharts は非推奨です。
// react-highcharts: Deprecated
// DO NOT USE in new projects
import ReactHighcharts from 'react-highcharts';
react-chartjs-2 はオープンソースです。
// react-chartjs-2: MIT License
import { Line } from 'react-chartjs-2';
recharts もオープンソースです。
// recharts: MIT License
import { LineChart } from 'recharts';
これら 4 つのライブラリは、異なるアプローチを取りながらも、いくつかの重要な共通点を持っています。
// All support basic charts
// recharts
<LineChart data={data}><Line dataKey="val" /></LineChart>
// react-chartjs-2
<Line data={data} />
// highcharts-react-official
<HighchartsReact options={{ chart: { type: 'line' } }} />
// react-highcharts
<ReactHighcharts config={{ chart: { type: 'line' } }} />
// Tooltip examples
// recharts
<Tooltip />
// react-chartjs-2 (via options)
options: { plugins: { tooltip: { enabled: true } } }
// highcharts-react-official (via options)
options: { tooltip: { enabled: true } }
// react-highcharts (via config)
config: { tooltip: { enabled: true } }
// Responsive setups
// recharts
<ResponsiveContainer width="100%" height={300}>...</ResponsiveContainer>
// react-chartjs-2
options: { responsive: true }
// highcharts-react-official
// Automatically resizes by default
// react-highcharts
// Supports resizing via config
| 特徴 | recharts | react-chartjs-2 | highcharts-react-official | react-highcharts |
|---|---|---|---|---|
| 描画 | SVG | Canvas | SVG | SVG |
| 統合 | ネイティブコンポーネント | ラッパー | ラッパー | ラッパー (旧) |
| ライセンス | MIT (無料) | MIT (無料) | 商用有料 | 商用有料 (旧) |
| 維持性 | 活発 | 活発 | 公式サポート | 非推奨 |
| 学習曲線 | 中 (React 知識必要) | 低 (設定オブジェクト) | 中 (Highcharts 知識) | 低 (だが非推奨) |
recharts は、React アプリケーションに自然に溶け込む图表が必要な場合に最適です。コンポーネントベースの設計により、カスタマイズが容易で、SVG ベースのためスタイル調整も直感的です。
react-chartjs-2 は、大量のデータを扱う場合や、Canvas ベースの性能が必要な場合に適しています。設定オブジェクトベースのため、複雑なカスタマイズには限界がありますが、標準的な用途には十分です。
highcharts-react-official は、高機能なエンタープライズ图表が必要で、予算がある場合に選択します。豊富な機能と公式サポートが魅力ですが、ライセンスコストを考慮する必要があります。
react-highcharts は、新規プロジェクトでは使用しないでください。公式の highcharts-react-official へ移行すべきです。
これらの選択は、プロジェクトの規模、予算、そしてチームの技術スタックに依存します。それぞれの特徴を理解し、最適なツールを選定することが重要です。
React の宣言的アプローチを重視し、カスタマイズ性と SVG ベースの柔軟性を求める場合に最適です。コンポーネントベースで制御しやすく、MIT ライセンスで無料です。
軽量でシンプルな图表が良く、Canvas ベースの性能が必要な場合に適しています。MIT ライセンスで無料利用でき、設定オブジェクトベースのため学習コストが低いです。
高機能なエンタープライズ图表が必要で、ライセンス購入が可能な場合に選択します。公式サポートがあり、複雑な图表要件にも対応できますが、商用利用にはコストがかかります。
既存のレガシーコード維持以外では新規採用は非推奨です。公式の highcharts-react-official へ移行すべきであり、維持が停止されている可能性があります。
Recharts is a Redefined chart library built with React and D3.
The main purpose of this library is to help you to write charts in React applications without any pain. Main principles of Recharts are:
Documentation at recharts.github.io and our storybook
Also see the wiki.
All development is done on the main branch. The current latest release and storybook documentation reflects what is on the release branch.
<LineChart width={400} height={400} data={data}>
<XAxis dataKey="name" />
<Tooltip />
<CartesianGrid stroke="#f5f5f5" />
<Line type="monotone" dataKey="uv" stroke="#ff7300" />
<Line type="monotone" dataKey="pv" stroke="#387908" />
</LineChart>
All the components of Recharts are clearly separated. The LineChart is composed of x axis, tooltip, grid, and line items, and each of them is an independent React Component. The clear separation and composition of components is one of the principle Recharts follows.
NPM is the easiest and fastest way to get started using Recharts. It is also the recommended installation method when building single-page applications (SPAs). It pairs nicely with a CommonJS module bundler such as Webpack.
# latest stable
$ npm install recharts react-is
react-is needs to match the version of your installed react package.
The UMD build is also available on unpkg.com:
<script src="https://unpkg.com/react/umd/react.production.min.js"></script>
<script src="https://unpkg.com/react-dom/umd/react-dom.production.min.js"></script>
<script src="https://unpkg.com/react-is/umd/react-is.production.min.js"></script>
<script src="https://unpkg.com/recharts/umd/Recharts.min.js"></script>
Then you can find the library on window.Recharts.
Recharts is open source. If you want to contribute to the project, please read the CONTRIBUTING.md to understand how to contribute to the project and DEVELOPING.md to set up your development environment.
Thanks to Chromatic for providing the visual testing platform that helps us review UI changes and catch visual regressions.
Thanks to JetBrains for providing OSS development license for their IDEs.
Browser testing via
Copyright (c) 2015-2024 Recharts Group.