lineEcharts.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  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('0');
  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 hader = ['日期', '数量']
  71. let data = props.propsData.xData.map((ele,index) => {
  72. return {
  73. '日期':ele,
  74. '数量':props.propsData.yData && props.propsData.yData[index] || 0,
  75. }
  76. })
  77. exportElsxFile(hader,data,'用户趋势')
  78. }
  79. watch(
  80. () => props.propsData,
  81. (propsData) => {
  82. setOptions({
  83. tooltip: {
  84. trigger: 'axis',
  85. axisPointer: {
  86. label: {
  87. show: true,
  88. backgroundColor: '#fff',
  89. color: '#556677',
  90. borderColor: 'rgba(0,0,0,0)',
  91. shadowColor: 'rgba(0,0,0,0)',
  92. shadowOffsetY: 0,
  93. },
  94. lineStyle: {
  95. width: 0,
  96. },
  97. },
  98. backgroundColor: '#fff',
  99. textStyle: {
  100. color: '#5c6c7c',
  101. },
  102. padding: [10, 10],
  103. extraCssText: 'box-shadow: 1px 0 2px 0 rgba(163,163,163,0.5)',
  104. },
  105. xAxis: {
  106. type: 'category',
  107. data: propsData.xData,
  108. },
  109. yAxis: [
  110. {
  111. type: 'value',
  112. axisTick: {
  113. show: false,
  114. },
  115. splitLine: {
  116. show: true,
  117. lineStyle: {
  118. color: ['#f1f4f8'],
  119. width: 1,
  120. type: 'solid',
  121. },
  122. },
  123. axisLabel: {
  124. textStyle: {
  125. color: '#556677',
  126. },
  127. formatter: '{value}',
  128. },
  129. axisLine: {
  130. show: false,
  131. lineStyle: {
  132. color: '#DCE2E8',
  133. },
  134. },
  135. },
  136. ],
  137. series: [
  138. {
  139. name: 'Adidas',
  140. type: 'line',
  141. data: propsData.yData,
  142. symbolSize: 1,
  143. smooth: true,
  144. symbol:'none', //加这个
  145. // yAxisIndex: 0,
  146. showSymbol: false,
  147. lineStyle: {
  148. width: 2,
  149. color: colorList[0],
  150. shadowColor: shadowColor[0],
  151. shadowBlur: 10,
  152. shadowOffsetY: 20,
  153. },
  154. },
  155. ],
  156. });
  157. },
  158. { immediate: true,deep:true },
  159. );
  160. </script>