Guest User

Untitled

a guest
Jan 19th, 2018
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.68 KB | None | 0 0
  1. const {BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, Legend} = Recharts;
  2. const data = [
  3. {name: 'Page A', uv: 4000, pv: 2400, amt: 2400},
  4. {name: 'Page B', uv: 3000, pv: 1398, amt: 2210},
  5. {name: 'Page C', uv: 2000, pv: 9800, amt: 2290},
  6. {name: 'Page D', uv: 2780, pv: 3908, amt: 2000},
  7. {name: 'Page E', uv: 1890, pv: 4800, amt: 2181},
  8. {name: 'Page F', uv: 2390, pv: 3800, amt: 2500},
  9. {name: 'Page G', uv: 3490, pv: 4300, amt: 2100},
  10. ];
  11.  
  12. const Pattern = ({id, fill="#666", stroke="#333"}) => {
  13. 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>;
  14. }
  15.  
  16. const numFormat = new Intl.NumberFormat('en', {
  17. style: 'currency',
  18. currency: 'USD',
  19. currencyDisplay: 'symbol',
  20. minimumFractionDigits: 1,
  21. maximumFractionDigits: 1,
  22. });
  23.  
  24. const tickFormatter= (val) => `${numFormat.format(val/1000)}k`;
  25.  
  26. const SimpleLineChart = React.createClass({
  27. render () {
  28. return (
  29. <BarChart layout="vertical" width={600} height={300} data={data}
  30. margin={{top: 20, right: 30, left: 20, bottom: 5}}>
  31. <defs><Pattern id="lines" /></defs>
  32. <XAxis type="number" tickFormatter={tickFormatter}/>
  33. <YAxis dataKey="name" type="category"/>
  34. <CartesianGrid strokeDasharray="3 3"/>
  35. <Tooltip/>
  36. <Legend />
  37. <Bar dataKey="pv" stackId="a" fill="url(#lines)" />
  38. <Bar dataKey="uv" stackId="a" fill="#82ca9d" />
  39. </BarChart>
  40. );
  41. }
  42. })
  43.  
  44. ReactDOM.render(
  45. <SimpleLineChart />,
  46. document.getElementById('container')
  47. );
Add Comment
Please, Sign In to add comment