A bar chart which has negative and positive values

by Zatcepin

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, ReferenceLine, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts;
const data = [
      {name: 'Page A', uv: 7},
      {name: 'Page B', uv: -1.5,}
];
const SimpleBarChart = React.createClass({
	render () {
  	return (
    	<BarChart 
      layout="vertical"
      width={600} height={300}
      data={data} >
       <XAxis dataKey="uv" hide />
       <XAxis xAxisId="ref" hide />
       <YAxis hide />
       <ReferenceLine xAxisId="ref" x={1} stroke='#000'/>
       <Bar dataKey="uv" fill="#8884d8" />
      </BarChart>
    );
  }
})

ReactDOM.render(
  <SimpleBarChart />,
  document.getElementById('container')
);