Skip to content

Commit f14a969

Browse files
author
ppotaczek
committed
Added option and corrections to the docs.
1 parent b64eb01 commit f14a969

11 files changed

+115
-10
lines changed

README.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ Official minimal [Highcharts](https://www.highcharts.com/) wrapper for React.
1717
3. [constructorType](#constructorType)
1818
4. [allowChartUpdate](#allowChartUpdate)
1919
5. [updateArgs](#updateArgs)
20-
6. [callback](#callback)
20+
6. [containerProps](#containerProps)
21+
7. [callback](#callback)
2122
3. [Example with custom chart component](#example-with-custom-chart-component)
2223
4. [Get repository](#get-repository)
2324
5. [Examples](#examples)
@@ -32,7 +33,7 @@ Make sure you have **node**, **NPM** and **React** up to date.
3233
Tested and required versions:
3334

3435
* node 8.11.3+
35-
* npm 6.4.1+
36+
* npm 6.4.1+ or similar package manager
3637
* React 16.4+
3738

3839
### Installing
@@ -181,6 +182,7 @@ Available options:
181182
constructorType={'mapChart'}
182183
allowChartUpdate={update}
183184
updateArgs={[true, true, true]}
185+
containerProps={{className: 'chartContainer'}}
184186
callback={this.chartCallback}
185187
/>
186188
```
@@ -212,6 +214,10 @@ Option `allowChartUpdate` allow to turn off the updating. This options is option
212214

213215
Array of `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](https://api.highcharts.com/class-reference/Highcharts.Chart#update) is a more specific description of the parameters. This option is optional.
214216

217+
### containerProps
218+
219+
The props object passed to the chart container in `React.createElement` method. Useful for adding styles or class.
220+
215221
### callback
216222

217223
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.
@@ -275,7 +281,7 @@ npm install highcharts
275281

276282
## Examples
277283

278-
There are several interesting examples in the demo folder that use all available constructors and a few modules.
284+
There are several interesting examples in the demo folder that use all available constructors and several modules.
279285

280286
Bundle these with:
281287

@@ -285,6 +291,8 @@ npm run build-demo
285291

286292
Demo is located under demo/index.html
287293

294+
Live example on codesandbox: https://codesandbox.io/s/rmjw8347po
295+
288296
## Tests
289297

290298
This wrapper contains tests for: testing environment, chart rendering and passing down container props.
@@ -298,10 +306,83 @@ npm run test
298306

299307
### Where to look for help?
300308

301-
[Technical support](https://www.highcharts.com/support) will help you with Highcharts and the wrapper.
309+
[Technical support](https://www.highcharts.com/support) will help you with Highcharts and with the wrapper.
302310

303311
If you have a bug to report or an enhancement suggestion please submit [Issues](https://github.com/highcharts/highcharts-react/issues) in this repository.
304312

305313
### Why highcharts-react-official, and not highcharts-react, is used?
306314

307315
The NPM package is registered as `highcharts-react-official` because `highcharts-react` was already taken.
316+
317+
### How to get a chart instance?
318+
319+
Use the `React.createRef` method:
320+
321+
```jsx
322+
componentDidMount() {
323+
this.chartRef = React.createRef();
324+
}
325+
326+
render() {
327+
return (
328+
<HighchartsReact
329+
highcharts={ Highcharts }
330+
options={ options }
331+
ref={ this.chartRef }
332+
/>
333+
);
334+
}
335+
```
336+
337+
or store it by the callback function:
338+
339+
```jsx
340+
constructor(props) {
341+
super(props);
342+
this.afterChartCreated = this.afterChartCreated.bind(this);
343+
}
344+
345+
afterChartCreated(chart) {
346+
this.internalChart = chart;
347+
}
348+
349+
componentDidMount() {
350+
// example of use
351+
this.internalChart.addSeries({ data: [1, 2, 3] })
352+
}
353+
354+
render() {
355+
return (
356+
<div>
357+
<h2>Highcharts</h2>
358+
<HighchartsReact
359+
highcharts={ Highcharts }
360+
options={ options }
361+
callback={ this.afterChartCreated }
362+
/>
363+
</div>
364+
);
365+
}
366+
```
367+
368+
### How to add a module?
369+
370+
To add a module, import and initialize it:
371+
372+
```jsx
373+
import Highcharts from 'highcharts'
374+
import highchartsGantt from "highcharts/modules/gantt";
375+
import HighchartsReact from 'highcharts-react-official'
376+
377+
// init the module
378+
highchartsGantt(Highcharts);
379+
```
380+
381+
or use `require`:
382+
383+
```jsx
384+
import Highcharts from 'highcharts'
385+
import HighchartsReact from 'highcharts-react-official'
386+
387+
require("highcharts/modules/variwide")(Highcharts);
388+
```

dist/highcharts-react.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export interface HighchartsReactProps {
4545
*/
4646
updateArgs?: ([boolean] | [boolean, boolean] | [boolean, boolean, boolean]);
4747

48+
/**
49+
* Properties of the chart container
50+
*/
51+
containerProps?: { [key: (number | string)]: any}
52+
4853

4954
/**
5055
* Callback for the chart factory

dist/highcharts-react.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/highcharts-react.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/highcharts-react.min.d.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@ export interface HighchartsReactProps {
4545
*/
4646
updateArgs?: ([boolean] | [boolean, boolean] | [boolean, boolean, boolean]);
4747

48+
/**
49+
* Properties of the chart container
50+
*/
51+
containerProps?: { [key: (number | string)]: any}
52+
4853

4954
/**
5055
* Callback for the chart factory

0 commit comments

Comments
 (0)