react-highcharts
Version:
React wrapper for highcharts
120 lines (88 loc) • 4.06 kB
Markdown
react-highcharts
================
[](https://travis-ci.org/kirjs/react-highcharts)
[](https://www.highcharts.com/documentation/changelog) component for react.
For highcharts 5.x.x use v. 13.0.0
[](http://kirjs.github.io/react-highcharts/)
| [react-highcharts/more](http://kirjs.github.io/react-highcharts/more.html)
| [react-highcharts/highstock](http://kirjs.github.io/react-highcharts/highstock.html)
| [react-highcharts/highmaps](http://kirjs.github.io/react-highcharts/highmaps.html)
You can also see [Code for the demo](https://github.com/kirjs/react-highcharts/tree/master/demo) and
[](https://github.com/kirjs/react-highcharts#running-demo)
```bash
npm install react-highcharts --save
```
```bash
npm install react-highcharts highcharts react --save
```
```jsx
const React = require('react');
const ReactDOM = require('react-dom');
const ReactHighcharts = require('react-highcharts'); // Expects that Highcharts was loaded in the code.
const config = {
/* HighchartsConfig */
};
ReactDOM.render(<ReactHighcharts config = {config}></ReactHighcharts>, document.body);
```
```jsx
const afterRender = (chart) => { /* do stuff with the chart */ };
<ReactHighcharts config = {config} callback = {afterRender}></ReactHighcharts>
```
```jsx
<ReactHighcharts config = {config} domProps = {{id: 'chartId'}}></ReactHighcharts>
```
For access to methods & properties from the Highcharts library you can use `ReactHighcharts.Highcharts`.
For example, the Highcharts options are available via `ReactHighcharts.Highcharts.getOptions()`.
Highcharts provides an API for manipulating a chart after the initial render. See the **Methods and Properties** in [the documentation](http://api.highcharts.com/highcharts). Here's how you access it:
```jsx
class MyComponent extends React.Component {
componentDidMount() {
let chart = this.refs.chart.getChart();
chart.series[0].addPoint({x: 10, y: 12});
}
render() {
return <ReactHighcharts config={config} ref="chart"></ReactHighcharts>;
}
}
```
Rerendering a highcharts graph is expensive. You can pass in a `isPureConfig` option to the `ReactHighcharts` component, which will keep the highcharts graph from being updated so long as the provided `config` is [referentially equal](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators) to its previous value.
There is also `neverReflow` property.
See this [recipe](https://github.com/kirjs/react-highcharts/blob/master/recipes.md#rendering-react-highcharts-on-node)
```javascript
const ReactHighmaps = require('react-highcharts/ReactHighmaps');
```
```javascript
const ReactHighstock = require('react-highcharts/ReactHighstock')
```
Use `highcharts-more` npm package.
```javascript
const ReactHighcharts = require('react-highcharts')
require('highcharts-more')(ReactHighcharts.Highcharts)
```
You can find the full list [here](https://github.com/kirjs/publish-highcharts-modules/blob/master/modules.md)
```javascript
const ReactHighcharts = require('react-highcharts').withHighcharts(ReactHighstock)
```
Run `npm test`
```bash
git clone https://github.com/kirjs/react-highcharts.git
cd react-highcharts && npm install
npm run demo
```
Point your browser at [http://localhost:8080](http://localhost:8080)