VisitAnalysis.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }"></div>
  3. </template>
  4. <script lang="ts">
  5. import { basicProps } from './props';
  6. // import { dateUtil } from '/@/utils/dateUtil';
  7. </script>
  8. <script lang="ts" setup>
  9. import { ref, Ref, watch } from 'vue';
  10. import { useECharts } from '/@/hooks/web/useECharts';
  11. const props = defineProps({
  12. ...basicProps,
  13. });
  14. const bulletChatAmountsData = ref<number[]>([]);
  15. const userAmountData = ref<number[]>([]);
  16. const yixStringData = ref<string[]>([]);
  17. const maxSize = ref(0);
  18. const chartRef = ref<HTMLDivElement | null>(null);
  19. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  20. function handleSetOptions() {
  21. setOptions({
  22. tooltip: {
  23. trigger: 'axis',
  24. axisPointer: {
  25. lineStyle: {
  26. width: 1,
  27. color: '#019680',
  28. },
  29. },
  30. },
  31. legend: {
  32. orient: 'horizontal',
  33. bottom: 0,
  34. },
  35. xAxis: {
  36. type: 'category',
  37. data: yixStringData.value,
  38. splitLine: {
  39. show: true,
  40. lineStyle: {
  41. width: 1,
  42. type: 'solid',
  43. color: 'rgba(226,226,226,0.5)',
  44. },
  45. },
  46. axisTick: {
  47. show: false,
  48. },
  49. },
  50. yAxis: [
  51. {
  52. type: 'value',
  53. max: maxSize.value,
  54. splitNumber: 4,
  55. axisTick: {
  56. show: false,
  57. },
  58. splitArea: {
  59. show: true,
  60. areaStyle: {
  61. color: ['rgba(255,255,255,0.2)', 'rgba(226,226,226,0.2)'],
  62. },
  63. },
  64. },
  65. ],
  66. grid: { left: '2%', right: '2%', top: '2%', bottom: '10%', containLabel: true },
  67. series: [
  68. {
  69. smooth: true,
  70. data: userAmountData.value,
  71. type: 'line',
  72. areaStyle: {},
  73. name: '留言总人数',
  74. itemStyle: {
  75. color: '#5ab1ef',
  76. },
  77. },
  78. {
  79. smooth: true,
  80. data: bulletChatAmountsData.value,
  81. type: 'line',
  82. name: '留言总数',
  83. areaStyle: {},
  84. itemStyle: {
  85. color: '#019680',
  86. },
  87. },
  88. ],
  89. });
  90. }
  91. watch(
  92. () => [props.bulletChatAmounts, props.userAmount],
  93. ([data1, data2]) => {
  94. bulletChatAmountsData.value = data1.reduce<number[]>(
  95. (prev: number[], current) => prev.concat(Number(current.amount)),
  96. [],
  97. );
  98. yixStringData.value = data1.reduce<string[]>(
  99. (prev: string[], current) => prev.concat(current.date),
  100. [],
  101. );
  102. userAmountData.value = data2.reduce<number[]>(
  103. (prev: number[], current) => prev.concat(Number(current.amount)),
  104. [],
  105. );
  106. console.log('viewStatics-data', bulletChatAmountsData.value);
  107. const maxNumber = Math.max(...bulletChatAmountsData.value.concat(userAmountData.value));
  108. const pow = Math.pow(10, maxNumber.toString().length - 1);
  109. maxSize.value = maxNumber > 10 ? Math.floor(maxNumber / 10) * 10 + pow * 2 : 10;
  110. console.log('maxSize', maxSize.value);
  111. handleSetOptions();
  112. // viewStaticsData.value = data;
  113. },
  114. {
  115. immediate: true,
  116. deep: true,
  117. },
  118. );
  119. </script>