SalesProductPie.vue 1.9 KB

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