Created
January 10, 2018 18:13
-
-
Save pragmasoft-ua/9f19dc56a8fe8f22c6810da53bd85845 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment