Official minimal Highcharts wrapper for React.
Table of Contents
- Getting started
- Options details
- Example with custom chart component
- Get repository
Make sure you have node, NPM and React up to date. Tested and required versions:
- node 8.11.3+
- npm 6.4.1+
- React 16.4+
Get package from NPM in your React app:
npm install highcharts-react-official
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 3const App = <div><HighchartsReact==/></div>
import React from 'react'import render from 'react-dom'import Highcharts from 'highcharts/highstock'import HighchartsReact from 'highcharts-react-official'const options =title:text: 'My stock chart'series:data: 1 2 3const App = <div><HighchartsReact===/></div>
import React from 'react'import render from 'react-dom'import Highcharts from 'highcharts'import HC_map from 'highcharts/modules/map'import HighchartsReact from 'highcharts-react-official'// init the module// instead of import + init you could use require as:// require('highcharts/modules/map')(Highcharts)// the same applies to any other Highcharts moduleconst options =title:text: 'My map chart'series:// any meaningful map data is much larger,// but it should go in heredata: 1 2 3const App = <div><HighchartsReact===/></div>
Highcharts chart configuration object. Please refer to the Highcharts API documentation. This option is required.
Used to pass the Highcharts instance after modules are initialized. If not set the component will try to get the Highcharts from window.
String for constructor method, defaults to
'chart'. Other official constructors are:
'stockChart'for Highstock charts
'mapChart'for Highmaps charts
If you have added a module or a plugin that adds new constructor then you can use it and set using this property.
This wrapper uses
chart.update() method to apply new options to the chart when changing the parent component.
allowChartUpdate allow to turn off the updating. This options is optional, defaults to
update()'s function optional arguments. Parameters should be defined in the same order like in native Highcharts function:
[redraw, oneToOne, animation], in this wrapper defaults to
[true, true, true]. Here is a more specific description of the parameters. This option is optional.
A callback function for the created chart. First argument for the function will hold the created
this in the function points to the
chart. This option is optional.
Example with custom chart component
Create custom component
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 3const MyStockChart = <HighchartsReact===/>
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>
Clone github repository and install dependencies:
git clone https://github.com/highcharts/highcharts-reactcd highcharts-reactnpm install
Examples and tests require Highcharts library, don't forget to:
npm install highcharts
There are several interesting examples in the demo folder that use all available constructors and a few modules.
Bundle these with:
npm run build-demo
Demo is located under demo/index.html
This wrapper contains tests for: testing environment, chart rendering and passing down container props. To run tests, type:
npm run test
Where to look for help?
Technical support will help you with Highcharts and the wrapper.
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 was already taken.