highcharts-react-official vs react-chartjs-2 vs react-highcharts vs recharts
React 图表ライブラリの選定とアーキテクチャ比較
highcharts-react-officialreact-chartjs-2react-highchartsrecharts類似パッケージ:

React 图表ライブラリの選定とアーキテクチャ比較

highcharts-react-officialreact-chartjs-2react-highchartsrecharts は、React アプリケーションでデータ可視化を実現するための主要なライブラリです。それぞれが異なるレンダリングエンジン(SVG または Canvas)と、React との統合アプローチ(ラッパーまたはネイティブコンポーネント)を採用しており、プロジェクトの要件に応じて適切な選択が必要です。

npmのダウンロードトレンド

3 年

GitHub Starsランキング

統計詳細

パッケージ
ダウンロード数
Stars
サイズ
Issues
公開日時
ライセンス
highcharts-react-official01,171241 kB148ヶ月前MIT
react-chartjs-206,93255.1 kB1077ヶ月前MIT
react-highcharts01,248-637年前-
recharts027,2176.76 MB4623ヶ月前MIT

React 图表ライブラリの深層比較:アーキテクチャ、描画エンジン、そして維持性

React エコシステムには多くの图表ライブラリが存在しますが、highcharts-react-officialreact-chartjs-2react-highchartsrecharts は特に注目すべき 4 つです。これらはそれぞれ異なる哲学を持っており、単に「グラフを描く」だけでなく、アプリケーションのパフォーマンス、メンテナンス性、ライセンスコストに直接影響します。

🎨 描画エンジン:SVG vs Canvas

recharts は SVG を使用します。

  • DOM 要素としてグラフを扱えるため、CSS や React イベントハンドラを直接使用できます。
  • 拡大縮小しても劣化しませんが、データポイントが極めて多い場合は重くなる可能性があります。
// 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 を使用します。

  • 1 つの <canvas> 要素に描画するため、DOM ノード数が少なく、大量データでも比較的高速です。
  • ただし、個別の要素へのアクセスは画像座標の計算が必要になります。
// react-chartjs-2: Canvas based
import { Line } from 'react-chartjs-2';
<Line data={chartData} options={chartOptions} />

highcharts-react-official は SVG を使用します。

  • Highcharts コアエンジンに基づき、インタラクティブな機能が豊富です。
  • SVG 構造はライブラリ内部で管理され、React から直接操作するものではありません。
// highcharts-react-official: SVG based
import HighchartsReact from 'highcharts-react-official';
<HighchartsReact highcharts={Highcharts} options={chartOptions} />

react-highcharts も SVG を使用します。

  • 内部的には Highcharts を使用しますが、ラッパーの実装が古く、現代の React 機能(フックなど)に完全には対応していません。
// react-highcharts: SVG based (Legacy)
import ReactHighcharts from 'react-highcharts';
<ReactHighcharts config={chartConfig} />

🧩 React との統合方法:ラッパー vs ネイティブ

recharts は React コンポーネントとして設計されています。

  • 图表の各部分(軸、ツールチップ、線)がコンポーネントとして構成されます。
  • React の状態管理やライフサイクルと自然に統合されます。
// recharts: Declarative Components
<BarChart data={data}>
  <XAxis dataKey="name" />
  <Bar dataKey="uv" fill="#8884d8" />
</BarChart>

react-chartjs-2 は Chart.js のラッパーです。

  • Chart.js の設定オブジェクトを props として渡します。
  • 图表の内部構造を React コンポーネントで細かく制御することはできません。
// react-chartjs-2: Configuration Object
const options = { responsive: true };
<Line options={options} data={data} />

highcharts-react-official もラッパーアプローチです。

  • Highcharts の設定オブジェクト(options)をそのまま渡します。
  • React の外側で Highcharts のインスタンスが管理されるため、状態更新時に注意が必要です。
// highcharts-react-official: Configuration Object
const options = { chart: { type: 'line' } };
<HighchartsReact options={options} />

react-highcharts は古いラッパーです。

  • 設定オブジェクトを渡しますが、React の更新サイクルとの相性に問題があることが報告されています。
// react-highcharts: Configuration Object
const config = { chart: { type: 'line' } };
<ReactHighcharts config={config} />

⚠️ 維持性とライセンス:公式サポートとコスト

highcharts-react-official は公式サポートがあります。

  • Highsoft 社によって維持されており、安定しています。
  • 商用利用にはライセンス購入が必要です。
// 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 はオープンソースです。

  • MIT ライセンスで、商用利用も無料です。
  • Chart.js コミュニティによって活発に維持されています。
// react-chartjs-2: MIT License
import { Line } from 'react-chartjs-2';

recharts もオープンソースです。

  • MIT ライセンスで、React エコシステムに最適化されています。
  • 多くの企業で採用されており、コミュニティが活発です。
// recharts: MIT License
import { LineChart } from 'recharts';

🤝 共通点:データ可視化の基礎

これら 4 つのライブラリは、異なるアプローチを取りながらも、いくつかの重要な共通点を持っています。

1. 📊 基本的な图表タイプのサポート

  • すべてが折れ線、棒、円グラフなどの基本类型をサポートしています。
  • 標準的なビジネスダッシュボードの要件は満たせます。
// 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' } }} />

2. 🖱️ インタラクティブ機能

  • ツールチップ、ズーム、パンなどの機能を提供します。
  • ユーザーがデータを探索するための手段を持っています。
// 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 } }

3. 📱 レスポンシブ対応

  • コンテナのサイズ変更に合わせてグラフを調整できます。
  • モバイルデバイスでの表示にも対応しています。
// 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

📊 比較サマリー

特徴rechartsreact-chartjs-2highcharts-react-officialreact-highcharts
描画SVGCanvasSVGSVG
統合ネイティブコンポーネントラッパーラッパーラッパー (旧)
ライセンスMIT (無料)MIT (無料)商用有料商用有料 (旧)
維持性活発活発公式サポート非推奨
学習曲線中 (React 知識必要)低 (設定オブジェクト)中 (Highcharts 知識)低 (だが非推奨)

💡 最終的な推奨

recharts は、React アプリケーションに自然に溶け込む图表が必要な場合に最適です。コンポーネントベースの設計により、カスタマイズが容易で、SVG ベースのためスタイル調整も直感的です。

react-chartjs-2 は、大量のデータを扱う場合や、Canvas ベースの性能が必要な場合に適しています。設定オブジェクトベースのため、複雑なカスタマイズには限界がありますが、標準的な用途には十分です。

highcharts-react-official は、高機能なエンタープライズ图表が必要で、予算がある場合に選択します。豊富な機能と公式サポートが魅力ですが、ライセンスコストを考慮する必要があります。

react-highcharts は、新規プロジェクトでは使用しないでください。公式の highcharts-react-official へ移行すべきです。

これらの選択は、プロジェクトの規模、予算、そしてチームの技術スタックに依存します。それぞれの特徴を理解し、最適なツールを選定することが重要です。

選び方: highcharts-react-official vs react-chartjs-2 vs react-highcharts vs recharts

  • highcharts-react-official:

    高機能なエンタープライズ图表が必要で、ライセンス購入が可能な場合に選択します。公式サポートがあり、複雑な图表要件にも対応できますが、商用利用にはコストがかかります。

  • react-chartjs-2:

    軽量でシンプルな图表が良く、Canvas ベースの性能が必要な場合に適しています。MIT ライセンスで無料利用でき、設定オブジェクトベースのため学習コストが低いです。

  • react-highcharts:

    既存のレガシーコード維持以外では新規採用は非推奨です。公式の highcharts-react-official へ移行すべきであり、維持が停止されている可能性があります。

  • recharts:

    React の宣言的アプローチを重視し、カスタマイズ性と SVG ベースの柔軟性を求める場合に最適です。コンポーネントベースで制御しやすく、MIT ライセンスで無料です。

highcharts-react-official のREADME

Highcharts React

Official minimal Highcharts integration for React.

Note: v4 of the Highcharts React integration is now available at @highcharts/react

Table of Contents

  1. Getting started
    1. General prerequisites
    2. Installing
    3. Using
      1. Basic usage example
      2. Highcharts with NextJS
      3. Highcharts with TypeScript
      4. Optimal way to update
  2. Options details
  3. Example with custom chart component
  4. Get repository
  5. Examples
  6. Tests
  7. Changelog
  8. FAQ
    1. Where to look for help?
    2. Why highcharts-react-official and not highcharts-react is used?
    3. How to get a chart instance?
    4. How to add a module?
    5. How to add React component to a chart's element?
    6. Why Highcharts mutates my data?

Getting Started

General prerequisites

Make sure you have node, NPM and React up to date. Tested and required versions:

  • node 8.11.3+
  • npm 6.4.1+ or similar package manager

This integration also requires highcharts and react packages with the following versions installed in your project:

For version 2.x.x :

  • react 16.4+
  • highcharts 5.0.0+

For version 3.x.x :

  • react 16.8+
  • highcharts 6.0.0+

Installing

Get the package from NPM in your React app:

npm install highcharts-react-official

If Highcharts is not already installed, get the package with Highcharts:

npm install highcharts highcharts-react-official

Using

Basic usage example

Import into your React project and render a chart:

import React from 'react'
import { render } from 'react-dom'
import Highcharts from 'highcharts'
import HighchartsReact from 'highcharts-react-official'

const options = {
  title: {
    text: 'My chart'
  },
  series: [{
    data: [1, 2, 3]
  }]
}

const App = () => <div>
  <HighchartsReact
    highcharts={Highcharts}
    options={options}
  />
</div>

render(<App />, document.getElementById('root'))

Highcharts with TypeScript

Live example: https://stackblitz.com/edit/react-starter-typescript-cfcznt

import React, { useRef } from 'react';
import * as Highcharts from 'highcharts';
import { HighchartsReact } from 'highcharts-react-official';

// The integration exports only a default component that at the same time is a
// namespace for the related Props interface (HighchartsReact.Props) and
// RefObject interface (HighchartsReact.RefObject). All other interfaces
// like Options come from the Highcharts module itself.

const options: Highcharts.Options = {
    title: {
        text: 'My chart'
    },
    series: [{
        type: 'line',
        data: [1, 2, 3]
    }]
};

const App = (props: HighchartsReact.Props) => {
  const chartComponentRef = useRef<HighchartsReact.RefObject>(null);

  return (
    <HighchartsReact
      highcharts={Highcharts}
      options={options}
      ref={chartComponentRef}
      {...props}
    />
  );
};
// Render your App component into the #root element of the document.
ReactDOM.render(<App />, document.getElementById('root'));

Since version 3.2.1 it is also possible to import types for props and ref independently:

import HighchartsReact, { HighchartsReactRefObject, HighchartsReactProps } from 'highcharts-react-official';

Highcharts with NextJS

Next.js executes code twice - on server-side and then client-side. First run is done in an environment that lacks window and causes Highcharts to be loaded, but not initialized. Easy fix is to place all modules inits in a if checking if Highcharts is an object or a function. It should be an object for modules initialization to work without any errors, so code like below is an easy fix:

import React from 'react'
import Highcharts from 'highcharts'
import HighchartsExporting from 'highcharts/modules/exporting'
import HighchartsReact from 'highcharts-react-official'

if (typeof Highcharts === 'object') {
    HighchartsExporting(Highcharts)
}

...

This is a know issue with NextJS and is covered here: https://github.com/vercel/next.js/issues/5354

Optimal way to update

A good practice is to keep all chart options in the state. When setState is called, the options are overwritten and only the new ones are passed to the chart.update method.

Live example: https://stackblitz.com/edit/react-hketvd?file=index.js

Optimal way to update with React Hooks: https://stackblitz.com/edit/react-nwseym?file=index.js

import React, { Component } from 'react';
import { render } from 'react-dom';
import HighchartsReact from 'highcharts-react-official';
import Highcharts from 'highcharts';

class LineChart extends Component {
  constructor(props) {
    super(props);

    this.state = {
      // To avoid unnecessary update keep all options in the state.
      chartOptions: {
        xAxis: {
          categories: ['A', 'B', 'C'],
        },
        series: [
          { data: [1, 2, 3] }
        ],
        plotOptions: {
          series: {
            point: {
              events: {
                mouseOver: this.setHoverData.bind(this)
              }
            }
          }
        }
      },
      hoverData: null
    };
  }

  setHoverData = (e) => {
    // The chart is not updated because `chartOptions` has not changed.
    this.setState({ hoverData: e.target.category })
  }

  updateSeries = () => {
    // The chart is updated only with new options.
    this.setState({
      chartOptions: {
        series: [
          { data: [Math.random() * 5, 2, 1]}
        ]
      }
    });
  }

  render() {
    const { chartOptions, hoverData } = this.state;

    return (
      <div>
        <HighchartsReact
          highcharts={Highcharts}
          options={chartOptions}
        />
      <h3>Hovering over {hoverData}</h3>
      <button onClick={this.updateSeries.bind(this)}>Update Series</button>
      </div>
    )
  }
}

render(<LineChart />, document.getElementById('root'));

Options details

Available options with example values:

  <HighchartsReact
    options = { this.state.chartOptions }
    highcharts = { Highcharts }
    constructorType = { 'mapChart' }
    allowChartUpdate = { true }
    immutable = { false }
    updateArgs = { [true, true, true] }
    containerProps = {{ className: 'chartContainer' }}
    callback = { this.chartCallback }
  />
ParameterTypeRequiredDefaultsDescription
optionsObjectyes-Highcharts chart configuration object. Please refer to the Highcharts API documentation.
highchartsObjectyes-Used to pass the Highcharts instance after modules are initialized. If not set the component will try to get the Highcharts from window.
constructorTypeStringno'chart'String for constructor method. Official constructors:
- 'chart' for Highcharts charts
- 'stockChart' for Highstock charts
- 'mapChart' for Highmaps charts
- 'ganttChart' for Gantt charts
allowChartUpdateBooleannotrueThis integration uses chart.update() method to apply new options to the chart when changing the parent component. This option allow to turn off the updating.
immutableBooleannofalseReinitialises the chart on prop update (as oppose to chart.update()) - useful in some cases but slower than a regular update.
updateArgsArrayno[true, true, true]Array of update()'s function optional arguments. Parameters should be defined in the same order like in native Highcharts function: [redraw, oneToOne, animation]. Here is a more specific description of the parameters.
containerPropsObjectno-The props object passed to the chart container in React.createElement method. Useful for adding styles or class.
callbackFunctionno-A callback function for the created chart. First argument for the function will hold the created chart. Default this in the function points to the chart. This option is optional.

Example with custom chart component

Create custom component ./components/MyStockChart.jsx:

import React from 'react'
import Highcharts from 'highcharts/highstock'
import HighchartsReact from 'highcharts-react-official'

const options = {
  title: {
    text: 'My stock chart'
  },
  series: [{
    data: [1, 2, 3]
  }]
}

const MyStockChart = () => <HighchartsReact
  highcharts={Highcharts}
  constructorType={'stockChart'}
  options={options}
/>

export default MyStockChart

Render your custom chart component like below:

import React from 'react'
import { render } from 'react-dom'
import MyStockChart from './components/MyStockChart.jsx'

const App = () => <div>
  <MyStockChart />
</div>

render(<App />, document.getElementById('root'))

Get repository

Clone github repository and install dependencies:

git clone https://github.com/highcharts/highcharts-react
cd highcharts-react
npm install

Examples and tests require Highcharts library, don't forget to:

npm install highcharts

Examples

There are several interesting examples in the demo folder that use all available constructors and several modules.

Bundle these with:

npm run build-demo

Demo is located under demo/index.html

Live example: https://stackblitz.com/edit/react-4ded5d?file=index.js

Tests

This integration contains tests for: testing environment, chart rendering and passing down container props. To run tests, type:

npm run test

Changelog

The changelog is available here.

FAQ

Where to look for help?

Technical support will help you with Highcharts and with the integration.

If you have a bug to report or an enhancement suggestion please submit Issues in this repository.

Why highcharts-react-official and not highcharts-react is used?

The NPM package is registered as highcharts-react-official because highcharts-react was already taken.

How to get a chart instance?

For class components and version prior to 3.0.0 use React.createRef:

constructor(props) {
  super(props)
  this.chartRef = React.createRef();
}

render() {
  return (
    <HighchartsReact
      highcharts={ Highcharts }
      options={ options }
      ref={ this.chartRef }
    />
  );
}

For functional components and version 3.0.0 and later use useRef hook:

  const chartComponent = useRef(null);
  const [options] = useState({...});

  useEffect(() => {
    const chart = chartComponent.current.chart;
    ...
  }, []);

  return <HighchartsReact ref={chartComponent} highcharts={Highcharts} options={options} />;

Alternatively store a chart reference in a callback function:

afterChartCreated = (chart) => {
  // Highcharts creates a separate chart instance during export
  if (!chart.options.chart.forExport) {
    this.internalChart = chart;
  }
}

componentDidMount() {
  // example of use
  this.internalChart.addSeries({ data: [1, 2, 3] })
}

render() {
  return (
    <div>
      <h2>Highcharts</h2>
      <HighchartsReact
        highcharts={ Highcharts }
        options={ options }
        callback={ this.afterChartCreated }
      />
    </div>
  );
}

How to add a module?

To add a module, import it like so:

import Highcharts from 'highcharts'
import highchartsGantt from "highcharts/modules/gantt"; // The Gantt module
import HighchartsReact from 'highcharts-react-official'

// Init the module (only for Highcharts v < 12)
if (typeof highchartsGantt === 'function') {
  highchartsGantt(Highcharts);
}

How to add React component to a chart's element?

By using Portals it is possible to add a component to every HTML chart element.

Live example: https://codesandbox.io/s/1o5y7r31k3

Why Highcharts mutates my data?

It can be confusing, since React props are read-only, but Highcharts for performance reasons mutates the original data array. This behaviour is NOT changed by our integration. You need to pass a copy of your data to the integration if you want to prevent mutations.

Issue: https://github.com/highcharts/highcharts-react/issues/326
More discussion here: https://github.com/highcharts/highcharts/issues/4259