AnalysisPie.vue 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }" />
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, onMounted, ref, Ref } from 'vue';
  6. import { useECharts } from '/@/hooks/web/useECharts';
  7. import { basicProps } from './props';
  8. const m2R2Data = [
  9. { value: 335, name: '移动设备', itemStyle: { color: '#1b65b9' } },
  10. { value: 310, name: '网页端', itemStyle: { color: '#3ca0f6' } },
  11. { value: 234, name: '手表', itemStyle: { color: '#2dc0c0' } },
  12. { value: 234, name: '其他', itemStyle: { color: '#7dd9b9' } },
  13. ];
  14. export default defineComponent({
  15. props: basicProps,
  16. setup() {
  17. const chartRef = ref<HTMLDivElement | null>(null);
  18. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  19. onMounted(() => {
  20. setOptions({
  21. title: [
  22. {
  23. text: '总设备',
  24. subtext: '1,430',
  25. textStyle: {
  26. fontSize: 12,
  27. color: '#4B535E85',
  28. },
  29. subtextStyle: {
  30. fontSize: 24,
  31. color: 'black',
  32. },
  33. textAlign: 'center',
  34. // @ts-ignore
  35. x: '34.5%',
  36. y: '40%',
  37. },
  38. ],
  39. tooltip: {
  40. trigger: 'item',
  41. backgroundColor: 'rgba(0, 0, 0, .6)',
  42. },
  43. legend: {
  44. icon: 'circle',
  45. itemHeight: 10,
  46. type: 'scroll',
  47. orient: 'vertical',
  48. left: '70%',
  49. align: 'left',
  50. top: 'middle',
  51. textStyle: {
  52. color: '#8C8C8C',
  53. },
  54. height: 250,
  55. },
  56. series: [
  57. {
  58. name: '成交额',
  59. type: 'pie',
  60. center: ['35%', '50%'],
  61. radius: ['45%', '65%'],
  62. label: {
  63. show: false,
  64. },
  65. data: m2R2Data,
  66. animationDuration: 3000,
  67. },
  68. ],
  69. });
  70. });
  71. return { chartRef };
  72. },
  73. });
  74. </script>