TimeSummaryChart.vue 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <el-card shadow="never">
  3. <template #header>
  4. <CardTitle :title="props.title" />
  5. </template>
  6. <!-- 折线图 -->
  7. <Echart :height="300" :options="lineChartOptions" />
  8. </el-card>
  9. </template>
  10. <script lang="ts" setup>
  11. import { EChartsOption } from 'echarts'
  12. import { formatDate } from '@/utils/formatTime'
  13. import { CardTitle } from '@/components/Card'
  14. import { propTypes } from '@/utils/propTypes'
  15. /** 会员用户统计卡片 */
  16. defineOptions({ name: 'MemberStatisticsCard' })
  17. const props = defineProps({
  18. title: propTypes.string.def('').isRequired,
  19. value: propTypes.object.isRequired
  20. })
  21. /** 折线图配置 */
  22. const lineChartOptions = reactive<EChartsOption>({
  23. dataset: {
  24. dimensions: ['time', 'price'],
  25. source: []
  26. },
  27. grid: {
  28. left: 20,
  29. right: 20,
  30. bottom: 20,
  31. top: 80,
  32. containLabel: true
  33. },
  34. legend: {
  35. top: 50
  36. },
  37. series: [{ name: '金额', type: 'line', smooth: true, areaStyle: {} }],
  38. toolbox: {
  39. feature: {
  40. // 数据区域缩放
  41. dataZoom: {
  42. yAxisIndex: false // Y轴不缩放
  43. },
  44. brush: {
  45. type: ['lineX', 'clear'] // 区域缩放按钮、还原按钮
  46. },
  47. saveAsImage: { show: true, name: props.title } // 保存为图片
  48. }
  49. },
  50. tooltip: {
  51. trigger: 'axis',
  52. axisPointer: {
  53. type: 'cross'
  54. },
  55. padding: [5, 10]
  56. },
  57. xAxis: {
  58. type: 'category',
  59. boundaryGap: false,
  60. axisTick: {
  61. show: false
  62. }
  63. },
  64. yAxis: {
  65. axisTick: {
  66. show: false
  67. }
  68. }
  69. }) as EChartsOption
  70. watch(
  71. () => props.value,
  72. (val) => {
  73. if (!val) {
  74. return
  75. }
  76. // 更新 Echarts 数据
  77. if (lineChartOptions.dataset && lineChartOptions.dataset['source']) {
  78. lineChartOptions.dataset['source'] = val
  79. }
  80. }
  81. )
  82. </script>