An area chart filled by the sign of value

by Rahul Desai

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, XAxis, YAxis, CartesianGrid, Tooltip} = Recharts;

const data1 = [
  {name: 'Page A', uv: 90},
  {name: 'Page B', uv: 90},
  {name: 'Page C', uv: 90},
  {name: 'Page D', uv: 90},
  {name: 'Page E', uv: 100},
  {name: 'Page F', uv: 90},
  {name: 'Page G', uv: 90},
];

const data2 = [
  {name: 'Page A', uv: 40},
  {name: 'Page B', uv: 30},
  {name: 'Page C', uv: 10},
  {name: 'Page D', uv: 50},
  {name: 'Page E', uv: 100},
  {name: 'Page F', uv: 25},
  {name: 'Page G', uv: 34},
];

const SimpleAreaChart = React.createClass({
	render () {
  	return (
    	<LineChart
        width={600}
        height={400}
        data={data2}
        margin={{top: 10, right: 30, left: 0, bottom: 0}}
      >
        <CartesianGrid strokeDasharray="3 3"/>
        <XAxis dataKey="name"/>
        <YAxis/>
        <Tooltip/>
        <defs>
          <linearGradient id="splitColor" x1="0" y1="0" x2="0" y2="1">
            <stop offset="0%" stopColor="green" stopOpacity={1}/>
            <stop offset="50%" stopColor="orange" stopOpacity={1}/>
            <stop offset="100%" stopColor="red" stopOpacity={1}/>
          </linearGradient>
        </defs>
        <Line type="monotone" dataKey="uv" stroke="url(#splitColor)" />
      </LineChart>
    );
  }
})

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