Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- const {BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts;
- const data = [
- {name: 'Page A', uv: 4000, pv: 2400, amt: 2400},
- {name: 'Page B', uv: 3000, pv: 1398, amt: 2210},
- {name: 'Page C', uv: 2000, pv: 9800, amt: 2290},
- {name: 'Page D', uv: 2780, pv: 3908, amt: 2000},
- {name: 'Page E', uv: 1890, pv: 4800, amt: 2181},
- {name: 'Page F', uv: 2390, pv: 3800, amt: 2500},
- {name: 'Page G', uv: 3490, pv: 4300, amt: 2100},
- ];
- const Pattern = ({id, fill="#666", stroke="#333"}) => {
- return <pattern id={id} patternUnits="userSpaceOnUse" width="8" height="8"><rect width="8" height="8" fill={fill}></rect><path d="M 0,8 l 8,-8 M -2,2 l 4,-4 M 6,10 l 4,-4" stroke-width="2" shape-rendering="auto" stroke={stroke} stroke-linecap="square"></path></pattern>;
- }
- const numFormat = new Intl.NumberFormat('en', {
- style: 'currency',
- currency: 'USD',
- currencyDisplay: 'symbol',
- minimumFractionDigits: 1,
- maximumFractionDigits: 1,
- });
- const tickFormatter= (val) => `${numFormat.format(val/1000)}k`;
- const SimpleLineChart = React.createClass({
- render () {
- return (
- <BarChart layout="vertical" width={600} height={300} data={data}
- margin={{top: 20, right: 30, left: 20, bottom: 5}}>
- <defs><Pattern id="lines" /></defs>
- <XAxis type="number" tickFormatter={tickFormatter}/>
- <YAxis dataKey="name" type="category"/>
- <CartesianGrid strokeDasharray="3 3"/>
- <Tooltip/>
- <Legend />
- <Bar dataKey="pv" stackId="a" fill="url(#lines)" />
- <Bar dataKey="uv" stackId="a" fill="#82ca9d" />
- </BarChart>
- );
- }
- })
- ReactDOM.render(
- <SimpleLineChart />,
- document.getElementById('container')
- );
Add Comment
Please, Sign In to add comment