SalesProductPie.vue 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <template>
  2. <Card title="成交占比" :loading="loading">
  3. <div ref="chartRef" :style="{ width, height }"></div>
  4. </Card>
  5. </template>
  6. <script lang="ts" setup>
  7. import { Ref, ref, watch } from 'vue';
  8. import { Card } from 'ant-design-vue';
  9. import { useECharts } from '/@/hooks/web/useECharts';
  10. const props = defineProps({
  11. loading: Boolean,
  12. width: {
  13. type: String as PropType<string>,
  14. default: '100%',
  15. },
  16. height: {
  17. type: String as PropType<string>,
  18. default: '300px',
  19. },
  20. });
  21. const chartRef = ref<HTMLDivElement | null>(null);
  22. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  23. watch(
  24. () => props.loading,
  25. () => {
  26. if (props.loading) {
  27. return;
  28. }
  29. setOptions({
  30. tooltip: {
  31. trigger: 'item',
  32. },
  33. series: [
  34. {
  35. name: '访问来源',
  36. type: 'pie',
  37. radius: '80%',
  38. center: ['50%', '50%'],
  39. color: ['#5ab1ef', '#b6a2de', '#67e0e3', '#2ec7c9'],
  40. data: [
  41. { value: 500, name: '电子产品' },
  42. { value: 310, name: '服装' },
  43. { value: 274, name: '化妆品' },
  44. { value: 400, name: '家居' },
  45. ].sort(function (a, b) {
  46. return a.value - b.value;
  47. }),
  48. roseType: 'radius',
  49. animationType: 'scale',
  50. animationEasing: 'exponentialInOut',
  51. animationDelay: function () {
  52. return Math.random() * 400;
  53. },
  54. },
  55. ],
  56. });
  57. },
  58. { immediate: true }
  59. );
  60. </script>