pieChart.tsx 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import React, { memo } from 'react'
  2. import { Pie, G2 } from '@ant-design/charts'
  3. import { PieConfig } from '@ant-design/charts/es/pie'
  4. import './index.scss'
  5. G2.registerTheme('custom-pie', {
  6. colors10: [ '#C7B8A1', '#9CA8B8', '#7B8B6F' ],
  7. colors29: [ '#DACAB1', '#ABB8CA', '#87987A' ]
  8. })
  9. type iPieChartProps = {
  10. type: string
  11. value: number
  12. }[]
  13. const DemoPie: React.FC<{data: iPieChartProps}> = ({ data }) => {
  14. const config:PieConfig = {
  15. appendPadding: 10,
  16. data,
  17. padding: 'auto',
  18. angleField: 'value',
  19. colorField: 'type',
  20. radius: 1,
  21. renderer: 'canvas',
  22. innerRadius: 0.7,
  23. className: 'echarts-pie',
  24. label: {
  25. type: 'outer',
  26. autoRotate: false,
  27. content: '{name}: {percentage}'
  28. },
  29. statistic: {
  30. title: false,
  31. content: false
  32. },
  33. interactions: [
  34. { type: 'element-selected' },
  35. // { type: 'pie-legend-active' },
  36. { type: 'element-active' }
  37. // { type: 'pie-statistic-active' }
  38. ],
  39. legend: {
  40. layout: 'horizontal',
  41. position: 'top-left'
  42. },
  43. theme: 'custom-pie'
  44. }
  45. return <Pie {...config} />
  46. }
  47. export default memo(DemoPie)