columnChart.tsx 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. import React, { memo } from 'react'
  2. import { DualAxes } from '@ant-design/charts'
  3. import { DualAxesConfig } from '@ant-design/charts/es/dualAxes'
  4. import { SafeColumnCharType, SafeLineChartType } from '@/pages/Safe/Content/Info/Summary'
  5. import { dayjsFormat } from '@/utils/util'
  6. // import { SafeColumnCharType, SafeLineChartType } from '.'
  7. interface iColumnChartProps {
  8. columnData: SafeColumnCharType[]
  9. lineData: SafeLineChartType[]
  10. }
  11. const ColumnChart: React.FC<{ data: iColumnChartProps }> = props => {
  12. const config: DualAxesConfig = {
  13. data: [ props.data.columnData, props.data.lineData ],
  14. xField: 'month',
  15. yField: [ 'count', 'percentage' ],
  16. padding: [ 20, 20, 60, 30 ],
  17. xAxis: {
  18. label: {
  19. formatter: (val) => dayjsFormat(val, 'YYYY年M月')
  20. }
  21. },
  22. slider: {},
  23. yAxis: {
  24. percentage: {
  25. label: {
  26. formatter: (val) => `${val} %`
  27. }
  28. }
  29. },
  30. tooltip: {
  31. formatter: datum => {
  32. const obj = { name: '', value: '' }
  33. if (Object.prototype.hasOwnProperty.call(datum, 'percentage')) {
  34. obj.name = '整改占总数比例'
  35. obj.value = datum.percentage + '%'
  36. } else if (datum.name && datum.name === 'rectifyed') {
  37. obj.name = '完成整改'
  38. obj.value = datum.count
  39. } else {
  40. obj.name = '提交巡检'
  41. obj.value = datum.count
  42. }
  43. return obj
  44. }
  45. },
  46. geometryOptions: [
  47. {
  48. geometry: 'column',
  49. isGroup: true,
  50. seriesField: 'name',
  51. columnWidthRatio: 0.4,
  52. color: ({ name }) => {
  53. if (name === 'rectifyed') {
  54. return '#D8CAAF'
  55. }
  56. return '#B5C4B1'
  57. },
  58. label: {}
  59. },
  60. {
  61. geometry: 'line',
  62. color: '#A06666',
  63. isStack: true,
  64. smooth: true
  65. }
  66. ],
  67. legend: {
  68. position: 'top',
  69. itemName: {
  70. formatter: (text: string) => {
  71. if (text === 'submit') {
  72. return '提交巡检'
  73. } else if (text === 'rectifyed') {
  74. return '完成整改'
  75. } else {
  76. return '整改占总数比例'
  77. }
  78. }
  79. }
  80. }
  81. }
  82. return <DualAxes {...config} />
  83. }
  84. export default memo(ColumnChart)