highcharts-react-official
Version:
Official minimal [Highcharts](https://www.highcharts.com/) wrapper for React.
384 lines (369 loc) • 14 kB
JSX
import React from 'react'
import { render } from 'react-dom'
// Import Highcharts
import Highcharts from 'highcharts/highstock'
// Import our demo components
import Chart from './components/Chart.jsx'
import StockChart from './components/Stock.jsx'
import MapChart from './components/Map.jsx'
import Container from './components/Container.jsx'
import mapData from './data/mapData.js'
// Load Highcharts modules
require('highcharts/indicators/indicators')(Highcharts)
require('highcharts/indicators/pivot-points')(Highcharts)
require('highcharts/indicators/macd')(Highcharts)
require('highcharts/modules/exporting')(Highcharts)
require('highcharts/modules/map')(Highcharts)
const chartOptions = {
title: {
text: ''
},
series: [{
data: [1,2,3],
}]
}
const stockOptions = {
yAxis: [{
height: '75%',
labels: {
align: 'right',
x: -3
},
title: {
text: 'AAPL'
}
}, {
top: '75%',
height: '25%',
labels: {
align: 'right',
x: -3
},
offset: 0,
title: {
text: 'MACD'
}
}],
series: [{
data: [
/* Jan 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Feb 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Mar 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Apr 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* May 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Jun 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Jul 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Aug 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Sep 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
[],
/* Oct 2017 */
[],
[],
[],
[],
[],
[],
[],
[],
[],
[]
],
type: 'ohlc',
name: 'AAPL Stock Price',
id: 'aapl'
}, {
type: 'pivotpoints',
linkedTo: 'aapl',
zIndex: 0,
lineWidth: 1,
dataLabels: {
overflow: 'none',
crop: false,
y: 4,
style: {
fontSize: 9
}
}
}, {
type: 'macd',
yAxis: 1,
linkedTo: 'aapl'
}]
}
const mapOptions = {
title: {
text: ''
},
colorAxis: {
min: 0,
stops: [
[],
[],
[]
]
},
tooltip: {
pointFormatter: function() {
return this.properties['woe-label'].split(',')[0];
}
},
series: [{
mapData: mapData,
dataLabels: {
formatter: function() {
return this.point.properties['woe-label'].split(',')[0];
}
},
name: 'Norway',
data: [
['no-mr', 0],
['no-st', 1],
['no-ho', 2],
['no-sf', 42],
['no-va', 4],
['no-of', 5],
['no-nt', 6],
['no-ro', 7],
['no-bu', 8],
['no-vf', 9],
['no-fi', 10],
['no-no', 11],
['no-tr', 12],
['no-ak', 13],
['no-op', 14],
['no-he', 15],
['no-os', 16],
['no-te', 17],
['no-aa', 18]
]
}]
}
// Render app with demo chart
class App extends React.Component {
constructor(props) {
super(props)
this.state = {
options: {
series: chartOptions.series
}
}
this.onClick = this.onClick.bind(this)
}
onClick() {
this.setState({
options: {
series: [{
data: [1, 2, 3]
},
{
data: [2, 3, 1]
},
{
data: [3, 2, 1]
}]
}
})
}
render() {
return <div>
<h1>Demos</h1>
<h2>Highcharts</h2>
<Chart options={this.state.options} highcharts={Highcharts} />
<button onClick={this.onClick}>Update Series</button>
<h2>Highstock</h2>
<StockChart options={stockOptions} highcharts={Highcharts} />
<h2>Highmaps</h2>
<MapChart options={mapOptions} highcharts={Highcharts} />
<h2>Live updating chart</h2>
<Container />
</div>
}
}
render(<App />, document.getElementById('root'))