index.tsx 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. import type { CSSProperties } from 'react'
  2. import { memo, useMemo } from 'react'
  3. import ReactECharts from 'echarts-for-react'
  4. import type { EChartsOption } from 'echarts'
  5. import style from './index.module.css'
  6. import classNames from '@/utils/classnames'
  7. export type SimplePieChartProps = {
  8. percentage?: number
  9. fill?: string
  10. stroke?: string
  11. size?: number
  12. className?: string
  13. }
  14. const SimplePieChart = ({ percentage = 80, fill = '#fdb022', stroke = '#f79009', size = 12, className }: SimplePieChartProps) => {
  15. const option: EChartsOption = useMemo(() => ({
  16. series: [
  17. {
  18. type: 'pie',
  19. radius: ['83%', '100%'],
  20. animation: false,
  21. data: [
  22. { value: 100, itemStyle: { color: stroke } },
  23. ],
  24. emphasis: {
  25. disabled: true,
  26. },
  27. labelLine: {
  28. show: false,
  29. },
  30. cursor: 'default',
  31. },
  32. {
  33. type: 'pie',
  34. radius: '83%',
  35. animationDuration: 600,
  36. data: [
  37. { value: percentage, itemStyle: { color: fill } },
  38. { value: 100 - percentage, itemStyle: { color: '#fff' } },
  39. ],
  40. emphasis: {
  41. disabled: true,
  42. },
  43. labelLine: {
  44. show: false,
  45. },
  46. cursor: 'default',
  47. },
  48. ],
  49. }), [stroke, fill, percentage])
  50. return (
  51. <ReactECharts
  52. option={option}
  53. className={classNames(style.simplePieChart, className)}
  54. style={{
  55. '--simple-pie-chart-color': fill,
  56. 'width': size,
  57. 'height': size,
  58. } as CSSProperties}
  59. />
  60. )
  61. }
  62. export default memo(SimplePieChart)