Synchronized charts
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/prop-types/prop-types.min.js"></script>
<script src="https://npmcdn.com/recharts/umd/Recharts.min.js"></script>
<div id="container">
<!-- This element's contents will be replaced with your component. -->
</div>
CSS
body {
margin: 0;
}
#container {
-webkit-box-sizing: border-box;
-moz-box-sizing: border-box;
box-sizing: border-box;
padding: 10px;
width: 800px;
height: 800px;
background-color: #fff;
}
Babel + JSX
const {LineChart, Line, AreaChart, Area, Brush, XAxis, YAxis, CartesianGrid, Tooltip} = Recharts;
const data = [
{name: 'Page A', uv: 4000, pv: 9000},
{name: 'Page B', uv: 3000, pv: 7222},
{name: 'Page C', uv: 2000, pv: 6222},
{name: 'Page D', uv: 1223, pv: 5400},
{name: 'Page E', uv: 1890, pv: 3200},
{name: 'Page F', uv: 2390, pv: 2500},
{name: 'Page G', uv: 3490, pv: 1209},
];
const SimpleAreaChart = React.createClass({
render () {
return (
<div>
<h4>A demo of synchronized AreaCharts</h4>
<LineChart width={600} height={200} data={data} syncId="anyId"
margin={{top: 10, right: 30, left: 0, bottom: 0}}>
<CartesianGrid strokeDasharray="3 3"/>
<XAxis dataKey="name"/>
<YAxis/>
<Tooltip/>
<Line type='monotone' dataKey='uv' stroke='#8884d8' fill='#8884d8' />
</LineChart>
<p>Maybe some other content</p>
<LineChart width={600} height={200} data={data} syncId="anyId"
margin={{top: 10, right: 30, left: 0, bottom: 0}}>
<CartesianGrid strokeDasharray="3 3"/>
<XAxis dataKey="name"/>
<YAxis/>
<Tooltip/>
<Line type='monotone' dataKey='pv' stroke='#82ca9d' fill='#82ca9d' />
</LineChart>
<AreaChart width={600} height={200} data={data} syncId="anyId"
margin={{top: 10, right: 30, left: 0, bottom: 0}}>
<CartesianGrid strokeDasharray="3 3"/>
<XAxis dataKey="name"/>
<YAxis/>
<Tooltip/>
<Area type='monotone' dataKey='pv' stroke='#82ca9d' fill='#82ca9d' />
</AreaChart>
</div>
);
}
})
ReactDOM.render(
<SimpleAreaChart />,
document.getElementById('container')
);