Bar.js 852 B

12345678910111213141516171819202122232425262728293031
  1. import React from 'react';
  2. import PropTypes from 'prop-types';
  3. import { BarChart, Bar, XAxis, YAxis, CartesianGrid, Tooltip, ResponsiveContainer } from 'recharts';
  4. import withTitle from './withTitle';
  5. const ChartBar = ({ data }) => (
  6. <ResponsiveContainer width="100%" height={window.innerWidth < 468 ? 240 : 320}>
  7. <BarChart
  8. data={data}
  9. layout="vertical"
  10. margin={{
  11. top: 0,
  12. right: 0,
  13. left: 24,
  14. bottom: 0,
  15. }}
  16. >
  17. <XAxis type="number" dataKey="value" />
  18. <YAxis type="category" dataKey="name" />
  19. <CartesianGrid strokeDasharray="1 1" />
  20. <Tooltip />
  21. <Bar dataKey="value" fill="#B39DDB" />
  22. </BarChart>
  23. </ResponsiveContainer>
  24. );
  25. ChartBar.propTypes = {
  26. data: PropTypes.arrayOf(PropTypes.object.isRequired).isRequired,
  27. };
  28. export default withTitle(ChartBar);