|
| 1 | +import React, { Component } from 'react'; |
| 2 | +import { |
| 3 | + HighchartsStockChart, Chart, XAxis, YAxis, Title, AreaSplineSeries, FlagSeries, Navigator, PlotBand |
| 4 | +} from 'react-jsx-highstock'; |
| 5 | +import ExampleCode from '../utils/ExampleCode'; |
| 6 | +import code from './exampleCode'; |
| 7 | +import { createRandomData } from '../utils/data-helpers'; |
| 8 | + |
| 9 | +class App extends Component { |
| 10 | + |
| 11 | + constructor (props) { |
| 12 | + super(props); |
| 13 | + |
| 14 | + this.renderPlotBand = this.renderPlotBand.bind(this); |
| 15 | + this.renderNavPlotBand = this.renderNavPlotBand.bind(this); |
| 16 | + |
| 17 | + const now = Date.now(); |
| 18 | + const unitSales = createRandomData(now, 1e8); |
| 19 | + this.state = { |
| 20 | + unitSales, |
| 21 | + campaigns: [ |
| 22 | + { |
| 23 | + from: unitSales[9][0], |
| 24 | + to: unitSales[23][0], |
| 25 | + title: 'US TV advert campaign' |
| 26 | + }, |
| 27 | + { |
| 28 | + from: unitSales[50][0], |
| 29 | + to: unitSales[57][0], |
| 30 | + title: 'UK Radio advert campaign' |
| 31 | + } |
| 32 | + ], |
| 33 | + notableEvents: [ |
| 34 | + { |
| 35 | + x: unitSales[0][0], |
| 36 | + title: 'North American Launch Date' |
| 37 | + }, |
| 38 | + { |
| 39 | + x: unitSales[30][0], |
| 40 | + title: 'European Launch Date' |
| 41 | + }, |
| 42 | + { |
| 43 | + x: unitSales[85][0], |
| 44 | + title: 'Asian Launch Date' |
| 45 | + } |
| 46 | + ] |
| 47 | + }; |
| 48 | + } |
| 49 | + |
| 50 | + renderPlotBand ({ from, to, title }) { |
| 51 | + const id = `band-${from}-${to}`; |
| 52 | + return ( |
| 53 | + <PlotBand id={id} key={id} from={from} to={to} color="rgba(68, 170, 213, 0.3)"> |
| 54 | + <PlotBand.Label>{title}</PlotBand.Label> |
| 55 | + </PlotBand> |
| 56 | + ); |
| 57 | + } |
| 58 | + |
| 59 | + renderNavPlotBand ({ from, to }) { |
| 60 | + const id = `nav-band-${from}-${to}`; |
| 61 | + return ( |
| 62 | + <PlotBand id={id} key={id} from={from} to={to} color="rgba(68, 170, 213, 0.3)" /> |
| 63 | + ); |
| 64 | + } |
| 65 | + |
| 66 | + render () { |
| 67 | + const { unitSales, notableEvents, campaigns } = this.state; |
| 68 | + |
| 69 | + return ( |
| 70 | + <div className="app"> |
| 71 | + <HighchartsStockChart> |
| 72 | + <Chart zoomType="x" /> |
| 73 | + |
| 74 | + <Title>Highstocks with Navigator Plot Bands</Title> |
| 75 | + |
| 76 | + <XAxis> |
| 77 | + <XAxis.Title>Date</XAxis.Title> |
| 78 | + {campaigns.map(this.renderPlotBand)} |
| 79 | + </XAxis> |
| 80 | + |
| 81 | + <YAxis id="sales"> |
| 82 | + <YAxis.Title>Cars sold per day</YAxis.Title> |
| 83 | + <AreaSplineSeries id="unitSales" name="Unit Sales" data={unitSales} /> |
| 84 | + <FlagSeries id="events" onSeries="unitSales" data={notableEvents} /> |
| 85 | + </YAxis> |
| 86 | + |
| 87 | + <Navigator> |
| 88 | + <Navigator.Series seriesId="unitSales" /> |
| 89 | + <Navigator.XAxis labels={{ x: 0, y: 12 }}> |
| 90 | + {campaigns.map(this.renderNavPlotBand)} |
| 91 | + </Navigator.XAxis> |
| 92 | + </Navigator> |
| 93 | + </HighchartsStockChart> |
| 94 | + |
| 95 | + <ExampleCode name="HighstockPlotBands">{code}</ExampleCode> |
| 96 | + |
| 97 | + </div> |
| 98 | + ); |
| 99 | + } |
| 100 | +} |
| 101 | + |
| 102 | +export default App; |
0 commit comments