Simple LineChart
A demo of simple lineChart of Recharts.
by Jaspal Marok
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, Area, Line, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ReferenceLine, ComposedChart} = Recharts;
const data = [
{month: "Feb", historical:4, current: 5, prediction:null},
{month: "Mar", historical:11, current: 10.5, prediction:null},
{month: "April", historical:12, current: 11, prediction:11},
{month:"June", historical:13, current:null, prediction:13},
{month:"July", historical:14, current:null, prediction:15},
{month:"August", historical:15, current:null, prediction:17}
];
const SimpleLineChart = React.createClass({
render () {
return (
<ComposedChart width={600} height={300} data={data}
margin={{top: 5, right: 30, left: 20, bottom: 5}}>
<XAxis dataKey="month" />
<YAxis />
<CartesianGrid strokeDasharray="3 3"/>
<Tooltip/>
<ReferenceLine y={15} label="Target Seats" stroke="red" />
<Area type="monotone" dataKey="current" fill="#8884d8" stroke="#8884d8" />
<Line type="monotone" dataKey="historical" stroke="#82ca9d" />
<Line type="monotone" dataKey="prediction" stroke="#8884d8" strokeDasharray="3 3" />
</ComposedChart>
);
}
})
ReactDOM.render(
<SimpleLineChart />,
document.getElementById('container')
);