React

by ucdl

HTML

<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.24/browser.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/react-with-addons.min.js"></script>
<script src="https://npmcdn.com/[email protected]/dist/react-dom.min.js"></script>
<script src="https://npmcdn.com/[email protected]/prop-types.min.js"></script>
<script src="https://npmcdn.com/[email protected]/umd/Recharts.min.js"></script>
<div id="app"></div>

CSS

#app {
  padding: 20px;
}

React

const { Area, AreaChart, ReferenceLine, XAxis, YAxis } = Recharts;

const data = [
      {name: 'A', uv: 4000, pv: 2400, amt: 2400},
      {name: 'B', uv: 3000, pv: 1398, amt: 2210},
      {name: 'C', uv: 2000, pv: 9800, amt: 2290},
      {name: 'D', uv: 2780, pv: 3908, amt: 2000},
      {name: 'E', uv: 1890, pv: 4800, amt: 2181},
      {name: 'F', uv: 2390, pv: 3800, amt: 2500},
      {name: 'G', uv: 3490, pv: 4300, amt: 2100},
];

class Chart extends React.Component {  
  render() {
    return (
    	<AreaChart width={600} height={300} data={data}>
        <Area type="monotone" dataKey="pv" fill="lightblue" strokeOpacity={0} />
        <XAxis dataKey="name"/>
        <YAxis/>
        
        // The viewBox attribute does not have any effect
        <ReferenceLine x="D" stroke="red" viewBox={{ y: 0, height: 0 }}/>
      </AreaChart>
    )
  }
}

ReactDOM.render(<Chart />, document.querySelector("#app"))