项目作者: kirjs

项目描述 :
React wrapper for Highcharts library
高级语言: JavaScript
项目地址: git://github.com/kirjs/react-highcharts.git
创建时间: 2015-03-11T16:26:47Z
项目社区:https://github.com/kirjs/react-highcharts

开源协议:MIT License

下载


react-highcharts

Build Status

Highcharts 6.x.x component for react.
For highcharts 5.x.x use v. 13.0.0

Demos

react-highcharts
| react-highcharts/more
| react-highcharts/highstock
| react-highcharts/highmaps

You can also see Code for the demo and
run demo locally

Installation

  1. npm install react-highcharts --save

Licensing

The React-Highcharts repository itself is MIT licensed,
however note that this module is dependent on Highcharts.js. For commercial use, you need a valid
Highcharts license.

Usage

Webpack/Browserify

  1. npm install react-highcharts highcharts react --save
  1. const React = require('react');
  2. const ReactDOM = require('react-dom');
  3. const ReactHighcharts = require('react-highcharts'); // Expects that Highcharts was loaded in the code.
  4. const config = {
  5. /* HighchartsConfig */
  6. };
  7. ReactDOM.render(<ReactHighcharts config = {config}></ReactHighcharts>, document.body);

Optional after-render callback

  1. const afterRender = (chart) => { /* do stuff with the chart */ };
  2. <ReactHighcharts config = {config} callback = {afterRender}></ReactHighcharts>

Passing properties to the wrapping DOM element

  1. <ReactHighcharts config = {config} domProps = {{id: 'chartId'}}></ReactHighcharts>

Accessing Highcharts API After Render

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. Here’s how you access it:

  1. class MyComponent extends React.Component {
  2. componentDidMount() {
  3. let chart = this.refs.chart.getChart();
  4. chart.series[0].addPoint({x: 10, y: 12});
  5. }
  6. render() {
  7. return <ReactHighcharts config={config} ref="chart"></ReactHighcharts>;
  8. }
  9. }

Limiting Highchart Rerenders

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 to its previous value.
There is also neverReflow property.

Rendering on the server with node

See this recipe

Using highmaps (demo)

  1. const ReactHighmaps = require('react-highcharts/ReactHighmaps');

Using highstock (demo)

  1. const ReactHighstock = require('react-highcharts/ReactHighstock')

Using highcharts modules/add-ons like exporting, data, etc. (demo)

Use highcharts-more npm package.

  1. const ReactHighcharts = require('react-highcharts')
  2. require('highcharts-more')(ReactHighcharts.Highcharts)

You can find the full list here

Passing Highcharts instance manually

  1. const ReactHighcharts = require('react-highcharts').withHighcharts(ReactHighstock)

For Contributors

Running tests

Run npm test

Running demo

  1. git clone https://github.com/kirjs/react-highcharts.git
  2. cd react-highcharts && npm install
  3. npm run demo

Point your browser at http://localhost:8080