npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

highcharts-react-official-fix

v2.0.0

Published

Official minimal [Highcharts](https://www.highcharts.com/) wrapper for React.

Downloads

35

Readme

Highcharts React

Official minimal Highcharts wrapper for React.

Table of Contents

  1. Getting started
    1. General prerequisites
    2. Installing
    3. Using
      1. Basic usage example
      2. Highcharts chart
      3. Highstock chart
      4. Highmaps chart
  2. Options details
    1. options
    2. highcharts
    3. constructorType
    4. allowChartUpdate
    5. updateArgs
    6. callback
  3. Example with custom chart component
  4. Get repository
  5. Examples
  6. Tests
  7. FAQ

Getting Started

General prerequisites

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+

Installing

Get package from NPM in your React app:

npm install highcharts-react-official

Using

Basic usage example

Import into your React project and render a chart:

Highcharts 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, 3]
  }]
}

const App = () => <div>
  <HighchartsReact
    highcharts={Highcharts}
    options={options}
  />
</div>

render(<App />, document.getElementById('root'))

Highstock chart

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, 3]
  }]
}

const App = () => <div>
  <HighchartsReact
    highcharts={Highcharts}
    constructorType={'stockChart'}
    options={options}
  />
</div>

render(<App />, document.getElementById('root'))

Highmaps chart

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
HC_map(Highcharts)

// instead of import + init you could use require as:
// require('highcharts/modules/map')(Highcharts)
// the same applies to any other Highcharts module

const options = {
  title: {
    text: 'My map chart'
  },
  series: [{
    // any meaningful map data is much larger,
    // but it should go in here
    data: [1, 2, 3]
  }]
}

const App = () => <div>
  <HighchartsReact
    highcharts={Highcharts}
    constructorType={'mapChart'}
    options={options}
  />
</div>

render(<App />, document.getElementById('root'))

Options details

Available options:

  <HighchartsReact
    options={options}
    highcharts={Highcharts}
    constructorType={'mapChart'}
    allowChartUpdate={update}
    updateArgs={[true, true, true]}
    callback={this.chartCallback}
  />

options

Highcharts chart configuration object. Please refer to the Highcharts API documentation. This option is required.

highcharts

Used to pass the Highcharts instance after modules are initialized. If not set the component will try to get the Highcharts from window.

constructorType

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.

allowChartUpdate

This wrapper uses chart.update() method to apply new options to the chart when changing the parent component. Option allowChartUpdate allow to turn off the updating. This options is optional, defaults to true.

updateArgs

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 is a more specific description of the parameters. This option is optional.

callback

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.

Example with custom chart component

Create custom component ./components/MyStockChart.jsx:

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, 3]
  }]
}

const MyStockChart = () => <HighchartsReact
  highcharts={Highcharts}
  constructorType={'stockChart'}
  options={options}
/>

export default MyStockChart

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>

render(<App />, document.getElementById('root'))

Get repository

Clone github repository and install dependencies:

git clone https://github.com/highcharts/highcharts-react
cd highcharts-react
npm install

Examples and tests require Highcharts library, don't forget to:

npm install highcharts

Examples

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

Tests

This wrapper contains tests for: testing environment, chart rendering and passing down container props. To run tests, type:

npm run test

FAQ

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-official because highcharts-react was already taken.