lineEcharts.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  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="value"
  9. style="width: 100px;margin-right:30px"
  10. placeholder="请选择颗粒度"
  11. :options="options"
  12. @change="handleChange"
  13. ></Select>
  14. </div>
  15. <a-button type="primary" @click="handleExport" >导出</a-button>
  16. </div>
  17. </template>
  18. <div ref="chartRef1" :style="{ width, height }"></div>
  19. </Card>
  20. </template>
  21. <script lang="ts" setup>
  22. import type { SelectProps } from 'ant-design-vue';
  23. import { Ref, ref, watch } from 'vue';
  24. import { Card, Select } from 'ant-design-vue';
  25. import { useECharts } from '/@/hooks/web/useECharts';
  26. const colorList = ['#38a0ff', '#73DDFF', '#fe9a8b', '#F56948', '#9E87FF'];
  27. const shadowColor = ['rgba(158,135,255, 0.3)','rgba(115,221,255, 0.3)','rgba(254,154,139, 0.3)']
  28. const emit = defineEmits(["alertSome"])
  29. import { exportElsxFile, } from '/@/utils/file/download';
  30. const props = defineProps({
  31. loading: Boolean,
  32. width: {
  33. type: String as PropType<string>,
  34. default: '100%',
  35. },
  36. height: {
  37. type: String as PropType<string>,
  38. default: '300px',
  39. },
  40. propsData:{
  41. type:Object,
  42. default:{
  43. xData:['北京', '上海', '广州', '深圳', '香港', '澳门', '台湾'],
  44. yData:[10, 10, 30, 12, 15, 3, 7],
  45. }
  46. }
  47. });
  48. const value = ref('2');
  49. const options = ref<SelectProps['options']>([
  50. {
  51. value: '0',
  52. label: '日',
  53. },
  54. {
  55. value: '1',
  56. label: '周',
  57. },
  58. {
  59. value: '2',
  60. label: '月',
  61. },
  62. ]);
  63. const chartRef1 = ref<HTMLDivElement | null>(null);
  64. const { setOptions } = useECharts(chartRef1 as Ref<HTMLDivElement>);
  65. function handleChange(val){
  66. emit('change',{type:'user',value:val})
  67. }
  68. function handleExport(){
  69. console.log('props',props.propsData)
  70. let fields = {
  71. 'time':'日期',
  72. 'num':'数量',
  73. }
  74. let data = props.propsData.xData.map((ele,index) => {
  75. return {
  76. 'time':ele,
  77. 'num':props.propsData.yData && props.propsData.yData[index] || 0,
  78. }
  79. })
  80. exportElsxFile(data, fields,'用户趋势')
  81. }
  82. watch(
  83. () => props.propsData,
  84. (propsData) => {
  85. setOptions({
  86. tooltip: {
  87. trigger: 'axis',
  88. axisPointer: {
  89. label: {
  90. show: true,
  91. backgroundColor: '#fff',
  92. color: '#556677',
  93. borderColor: 'rgba(0,0,0,0)',
  94. shadowColor: 'rgba(0,0,0,0)',
  95. shadowOffsetY: 0,
  96. },
  97. lineStyle: {
  98. width: 0,
  99. },
  100. },
  101. backgroundColor: '#fff',
  102. textStyle: {
  103. color: '#5c6c7c',
  104. },
  105. padding: [10, 10],
  106. extraCssText: 'box-shadow: 1px 0 2px 0 rgba(163,163,163,0.5)',
  107. },
  108. xAxis: {
  109. type: 'category',
  110. data: propsData.xData,
  111. },
  112. yAxis: [
  113. {
  114. type: 'value',
  115. axisTick: {
  116. show: false,
  117. },
  118. splitLine: {
  119. show: true,
  120. lineStyle: {
  121. color: ['#f1f4f8'],
  122. width: 1,
  123. type: 'solid',
  124. },
  125. },
  126. axisLabel: {
  127. textStyle: {
  128. color: '#556677',
  129. },
  130. formatter: '{value}',
  131. },
  132. axisLine: {
  133. show: false,
  134. lineStyle: {
  135. color: '#DCE2E8',
  136. },
  137. },
  138. },
  139. ],
  140. series: [
  141. {
  142. name: '用户趋势',
  143. type: 'line',
  144. data: propsData.yData,
  145. symbolSize: 1,
  146. smooth: true,
  147. symbol:'none', //加这个
  148. // yAxisIndex: 0,
  149. showSymbol: false,
  150. lineStyle: {
  151. width: 2,
  152. color: colorList[0],
  153. shadowColor: shadowColor[0],
  154. shadowBlur: 10,
  155. shadowOffsetY: 20,
  156. },
  157. },
  158. ],
  159. });
  160. },
  161. { immediate: true,deep:true },
  162. );
  163. </script>