index.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. import React from 'react';
  2. import './index.less';
  3. import PieChart from '@src/components/PieChart';
  4. function makePie(text, subtext, color, data) {
  5. return {
  6. title: {
  7. text,
  8. textAlign: 'center',
  9. textVerticalAlign: 'middle',
  10. textStyle: { fontSize: 14, color: '#686872' },
  11. subtext,
  12. subtextStyle: { fontSize: 16, color: '#303036' },
  13. top: '28%',
  14. left: '45%',
  15. },
  16. color,
  17. series: [
  18. {
  19. type: 'pie',
  20. radius: ['85%', '100%'],
  21. hoverAnimation: false,
  22. animation: false,
  23. label: {
  24. show: false,
  25. },
  26. data,
  27. },
  28. ],
  29. };
  30. }
  31. export default function Ratio(props) {
  32. const { text, subtext, values, size = 'basic' } = props;
  33. return (
  34. <div className={`ratio-pie ${size}`}>
  35. <PieChart
  36. width={size === 'small' ? 80 : 110}
  37. height={size === 'small' ? 80 : 110}
  38. option={makePie(text, subtext, values.map(item => item.color), values.map(item => item.value))}
  39. />
  40. <div className="label-list">
  41. {values.map(item => {
  42. return (
  43. <div className="item">
  44. <i style={{ backgroundColor: item.color }} />
  45. {item.label}
  46. </div>
  47. );
  48. })}
  49. </div>
  50. </div>
  51. );
  52. }