candlestick
candlestick with error bar
by coktopus
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 {BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend, ErrorBar} = Recharts;
const data = [
{name: 'Week 1', max: 4000, min: 1400, error: [200, 1000]},
{name: 'Week 2', max: 4000, min: 3400, errorNegative: [1000, 200]},
{name: 'Week 3', max: 3200, min: 2400, errorNegative: [1000, 200]},
{name: 'Week 4', max: 1000, min: 400, error: [200, 1000]},
{name: 'Week 5', max: 2000, min: 1100, error: [200, 1000]},
{name: 'Week 6', max: 3000, min: 400, error: [-200, 2000]},
{name: 'Week 7', max: 500, min: -1000, error: [200, 2000]},
];
const SimpleBarChart = React.createClass({
render () {
return (
<BarChart width={600} height={300} data={data}
margin={{top: 5, right: 30, left: 20, bottom: 5}}>
<XAxis xAxisId={0} dataKey="name" hide/>
<XAxis xAxisId={1} dataKey="name"/>
<YAxis/>
<Tooltip cursor={{fill: 'transparent'}}/>
<Bar barSize={30} xAxisId={0} dataKey="max" fill="#035aa6" />
<Bar barSize={35} xAxisId={1} dataKey='min' fill="white">
<ErrorBar dataKey="error" width={4} strokeWidth={2} stroke="#66c208" />
<ErrorBar dataKey="errorNegative" width={4} strokeWidth={2} stroke="#ff0044" />
</Bar>
</BarChart>
);
}
})
ReactDOM.render(
<SimpleBarChart />,
document.getElementById('container')
);