lineEcharts2.vue 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  1. <template>
  2. <Card title="订单数据统计" :loading="loading">
  3. <template #extra>
  4. <div class="condition">
  5. <div class="selct" style="display: inline-block;">
  6. <!-- <span style="margin-right:15px"></span> -->
  7. <Select
  8. v-model:value="type"
  9. style="width: 100px;margin-right:30px"
  10. placeholder="请选择颗粒度"
  11. :options="typeOptions"
  12. @change="handleType"
  13. ></Select>
  14. </div>
  15. <div class="selct" style="display: inline-block;margin-right:15px">
  16. <RangePicker v-model:value="selectTime" :picker="picker" />
  17. </div>
  18. <div class="selct" style="display: inline-block;">
  19. <!-- <span style="margin-right:15px">颗粒度</span> -->
  20. <Select
  21. v-model:value="value"
  22. style="width: 100px;margin-right:30px"
  23. placeholder="请选择颗粒度"
  24. :options="options"
  25. @change="handleData"
  26. ></Select>
  27. </div>
  28. <a-button type="primary" >导出</a-button>
  29. </div>
  30. </template>
  31. <div ref="chartRef" :style="{ height, width }"></div>
  32. </Card>
  33. </template>
  34. <script lang="ts">
  35. import { basicProps } from './props';
  36. // import { dateUtil } from '/@/utils/dateUtil';
  37. </script>
  38. <script lang="ts" setup>
  39. import { Card, Select, DatePicker } from 'ant-design-vue';
  40. const {RangePicker} = DatePicker;
  41. import { ref, Ref, watch } from 'vue';
  42. // import type { dataItemType } from './props';
  43. import { useECharts } from '/@/hooks/web/useECharts';
  44. import type { Dayjs } from 'dayjs';
  45. const props = defineProps({
  46. loading: Boolean,
  47. ...basicProps,
  48. });
  49. type RangeValue = [Dayjs, Dayjs];
  50. const picker = ref('date')
  51. const value = ref('1');
  52. const selectTime = ref<RangeValue>();
  53. const options = ref<SelectProps['options']>([
  54. {
  55. value: '1',
  56. label: '日',
  57. },
  58. {
  59. value: '2',
  60. label: '周',
  61. },
  62. {
  63. value: '2',
  64. label: '月',
  65. },
  66. ]);
  67. const type = ref('1');
  68. const typeOptions = ref<SelectProps['options']>([
  69. {
  70. value: '1',
  71. label: '数量',
  72. },
  73. {
  74. value: '2',
  75. label: '金额',
  76. },
  77. ]);
  78. const viewStaticsData = ref<number[]>([1,5,6,8,55,1,5,6,8,1]);
  79. const shareStaticsData = ref<number[]>([2,55,10,2,6,1,5,6,8,1]);
  80. const yixStringData = ref<string[]>(['11','22','33','44','ss','11','22','33','44','ss']);
  81. const maxSize = ref(0);
  82. const chartRef = ref<HTMLDivElement | null>(null);
  83. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  84. function handleData(val){
  85. let obj ={
  86. 1:'date',
  87. 2:'week',
  88. 3:'month',
  89. }
  90. console.log('handleChange',val)
  91. }
  92. function handleType(val){
  93. console.log('handleChange',val)
  94. }
  95. function handlesetOptions() {
  96. setOptions({
  97. tooltip: {
  98. trigger: 'axis',
  99. axisPointer: {
  100. lineStyle: {
  101. width: 1,
  102. color: '#019680',
  103. },
  104. },
  105. },
  106. legend: {
  107. orient: 'horizontal',
  108. bottom: 0,
  109. },
  110. // grid: { left: '2%', right: '2%', top: '10%', bottom: '10%', containLabel: true },
  111. xAxis: {
  112. type: 'category',
  113. // data: [...new Array(30)].map((_item, index) => `${index + 1}日`),
  114. data: yixStringData.value,
  115. },
  116. yAxis: {
  117. type: 'value',
  118. max: maxSize.value,
  119. splitNumber: 4,
  120. },
  121. series: [
  122. {
  123. data: viewStaticsData.value,
  124. type: 'line',
  125. itemStyle: { color: '#38a0ff' },
  126. // barMaxWidth: 80,
  127. name: '用户浏览量',
  128. },
  129. {
  130. data: shareStaticsData.value,
  131. type: 'line',
  132. itemStyle: { color: '#4cca73' },
  133. // barMaxWidth: 80,
  134. name: '用户分享数',
  135. },
  136. ],
  137. });
  138. }
  139. // props.viewStatics,
  140. watch(
  141. // () => [props.viewStatics, props.shareStatics],
  142. // ([data1, data2]) => {
  143. () => props.loading,
  144. () => {
  145. console.log('viewStatics-data');
  146. // viewStaticsData.value = data1.reduce<number[]>(
  147. // (prev: number[], current) => prev.concat(Number(current.amount)),
  148. // [],
  149. // );
  150. // yixStringData.value = data1.reduce<string[]>(
  151. // (prev: string[], current) => prev.concat(current.date),
  152. // [],
  153. // );
  154. // shareStaticsData.value = data2.reduce<number[]>(
  155. // (prev: number[], current) => prev.concat(Number(current.amount)),
  156. // [],
  157. // );
  158. const maxNumber = Math.max(...viewStaticsData.value.concat(shareStaticsData.value));
  159. const pow = Math.pow(10, maxNumber.toString().length - 1);
  160. maxSize.value = maxNumber > 10 ? Math.floor(maxNumber / 10) * 10 + pow * 2 : 10;
  161. console.log('maxSize', maxSize.value);
  162. handlesetOptions();
  163. },
  164. {
  165. immediate: true,
  166. deep: true,
  167. },
  168. );
  169. </script>