Highcharts Official React Integration (Legacy)

3.2.3 · deprecated · verified Sun Apr 19

highcharts-react-official is the previous official React wrapper for the Highcharts charting library, now largely superseded by the newer `@highcharts/react` package. This library (v3.2.3) provides a declarative way to integrate Highcharts, Highstock, and Highmaps into React applications, abstracting away direct DOM manipulation. It supports React versions 16.8.0 and above, and Highcharts core versions 6.0.0 and up. Key features include passing chart options as props, lifecycle management for updates and unmounting, and basic integration with Highcharts modules. While functional and widely used in existing projects, new projects are strongly encouraged to use `@highcharts/react` (v4+), which offers a more 'React-native' API, full ES module support, improved TypeScript definitions, and custom component integration. Releases for `highcharts-react-official` are infrequent as development has shifted to the new package. Its primary differentiator was being the official wrapper, providing a stable, maintained bridge between Highcharts and React before the newer, more opinionated integration was developed. It ships with TypeScript types.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart renders a basic Highcharts line chart, demonstrates how to import and apply a Highcharts module (Exporting), and shows how to update chart data reactively using React's `useState` hook. It also correctly passes the Highcharts instance and handles potential SSR issues for module loading.

import React, { useRef, useEffect, useState } from 'react';
import Highcharts from 'highcharts';
import HighchartsExporting from 'highcharts/modules/exporting';
import HighchartsReact from 'highcharts-react-official';

// Initialize Highcharts modules if Highcharts object is available
if (typeof Highcharts === 'object') {
  HighchartsExporting(Highcharts);
}

const MyChartComponent = () => {
  const chartComponentRef = useRef(null);
  const [options, setOptions] = useState({
    title: { text: 'My Sample Chart' },
    series: [{
      type: 'line',
      data: [1, 2, 4, 6, 8, 7, 5, 3, 2, 1]
    }],
    chart: {
      height: 400,
      width: 600
    },
    credits: { enabled: false },
    exporting: { enabled: true }
  });

  // Example of updating data after some time
  useEffect(() => {
    const timer = setTimeout(() => {
      setOptions(prevOptions => ({
        ...prevOptions,
        series: [{
          ...prevOptions.series[0],
          data: [5, 7, 9, 8, 6, 4, 2, 1, 3, 5]
        }]
      }));
    }, 3000);
    return () => clearTimeout(timer);
  }, []);

  return (
    <div>
      <h2>Highcharts with React</h2>
      <HighchartsReact
        highcharts={Highcharts}
        options={options}
        ref={chartComponentRef}
      />
      <p>This chart demonstrates basic line series, module integration (exporting), and reactive updates via component state.</p>
    </div>
  );
};

export default MyChartComponent;

view raw JSON →