index.tsx 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import {Column, ColumnConfig} from '@ant-design/charts';
  2. import moment from 'moment';
  3. import {useEffect} from 'react';
  4. import {service} from '@/pages/Analysis';
  5. const calculationDate = () => {
  6. const dd = new Date();
  7. dd.setDate(dd.getDate() - 30);
  8. const y = dd.getFullYear();
  9. const m = dd.getMonth() + 1 < 10 ? `0${dd.getMonth() + 1}` : dd.getMonth() + 1;
  10. const d = dd.getDate() < 10 ? `0${dd.getDate()}` : dd.getDate();
  11. return `${y}-${m}-${d} 00:00:00`;
  12. };
  13. const MessageChart = () => {
  14. const list = [
  15. {
  16. dashboard: 'device',
  17. object: 'message',
  18. measurement: 'quantity',
  19. dimension: 'agg',
  20. group: 'sameDay',
  21. params: {
  22. time: '1d',
  23. format: 'yyyy-MM-dd',
  24. },
  25. },
  26. {
  27. dashboard: 'device',
  28. object: 'message',
  29. measurement: 'quantity',
  30. dimension: 'agg',
  31. group: 'sameMonth',
  32. params: {
  33. limit: 30,
  34. time: '1d',
  35. format: 'yyyy-MM-dd',
  36. from: calculationDate(),
  37. to: `${moment(new Date()).format('YYYY-MM-DD')} 23:59:59`,
  38. },
  39. },
  40. {
  41. dashboard: 'device',
  42. object: 'message',
  43. measurement: 'quantity',
  44. dimension: 'agg',
  45. group: 'month',
  46. params: {
  47. time: '1M',
  48. format: 'yyyy-MM-dd',
  49. from: calculationDate(),
  50. to: `${moment(new Date()).format('YYYY-MM-DD')} 23:59:59`,
  51. },
  52. },
  53. ];
  54. useEffect(() => {
  55. service.getMulti(list).subscribe((data) => {
  56. console.log(data);
  57. });
  58. }, []);
  59. const data = [
  60. {
  61. type: '1-3秒',
  62. value: 0.16,
  63. },
  64. {
  65. type: '4-10秒',
  66. value: 0.125,
  67. },
  68. {
  69. type: '11-30秒',
  70. value: 0.24,
  71. },
  72. {
  73. type: '31-60秒',
  74. value: 0.19,
  75. },
  76. {
  77. type: '1-3分',
  78. value: 0.22,
  79. },
  80. {
  81. type: '3-10分',
  82. value: 0.05,
  83. },
  84. {
  85. type: '10-30分',
  86. value: 0.01,
  87. },
  88. {
  89. type: '30+分',
  90. value: 0.015,
  91. },
  92. ];
  93. const paletteSemanticRed = '#F4664A';
  94. const brandColor = '#5B8FF9';
  95. const config: ColumnConfig = {
  96. data,
  97. xField: 'type',
  98. yField: 'value',
  99. seriesField: '',
  100. color: function color(_ref: any) {
  101. const {type} = _ref;
  102. if (type === '10-30分' || type === '30+分') {
  103. return paletteSemanticRed;
  104. }
  105. return brandColor;
  106. },
  107. width: 200,
  108. height: 200,
  109. label: {
  110. offset: 10,
  111. },
  112. legend: false,
  113. xAxis: {
  114. label: {
  115. autoHide: true,
  116. autoRotate: false,
  117. },
  118. },
  119. };
  120. return <Column {...config} />;
  121. };
  122. export default MessageChart;