pieEchart.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. <template>
  2. <Card title="作品类型统计">
  3. <div class="piechart" ref="chartPieRef" :style="{ height: '280px', width: '100%' }"></div>
  4. </Card>
  5. </template>
  6. <script lang="ts" setup>
  7. import { Card } from 'ant-design-vue';
  8. import { ref, Ref, onMounted } from 'vue';
  9. import { workType } from '/@/api/statistics/index';
  10. import { useECharts } from '/@/hooks/web/useECharts';
  11. const chartPieRef = ref<HTMLDivElement | null>(null);
  12. const { setOptions } = useECharts(chartPieRef as Ref<HTMLDivElement>);
  13. const colorList = ['#38a0ff', '#4cca73', '#FDD56A', '#d58b55', '#c8ffff'];
  14. let pieData = ref([])
  15. var rich = {
  16. name: {
  17. color: '#666666',
  18. fontSize: 14,
  19. padding: [8, 30, 0, 30],
  20. fontWeight: '400',
  21. align: 'left',
  22. },
  23. value: {
  24. color: '#333',
  25. fontSize: 15,
  26. padding: [0, 30, 8, 30],
  27. fontWeight: '500',
  28. align: 'left',
  29. },
  30. percent: {
  31. color: '#FFF',
  32. align: 'right',
  33. fontSize: 15,
  34. fontWeight: '500',
  35. //padding: [0, 5]
  36. },
  37. hr: {
  38. borderColor: '#DFDFDF',
  39. width: '100%',
  40. borderWidth: 1,
  41. height: 0,
  42. },
  43. cir: {
  44. fontSize: 26,
  45. },
  46. };
  47. function handlesetOptions() {
  48. setOptions({
  49. tooltip: {
  50. trigger: 'item',
  51. formatter: '{b}<br/>数量 : {c} ({d}%)',
  52. },
  53. legend: {
  54. orient: 'horizontal',
  55. bottom: 0,
  56. },
  57. series: [
  58. {
  59. name: '库存情况',
  60. type: 'pie',
  61. radius: '68%',
  62. center: ['50%', '50%'],
  63. clockwise: false,
  64. data: pieData.value,
  65. label: {
  66. normal: {
  67. position: 'inner',
  68. formatter: (params) => {
  69. return '{percent|' + params.percent.toFixed(0) + '%}';
  70. },
  71. rich: rich,
  72. },
  73. },
  74. labelLine: {
  75. normal: {
  76. position: 'inner',
  77. formatter: (params) => {
  78. return '{percent|' + params.percent.toFixed(0) + '%}';
  79. },
  80. rich: rich,
  81. },
  82. },
  83. itemStyle: {
  84. borderWidth: 5,
  85. borderColor: '#fff',
  86. },
  87. },
  88. ],
  89. color: colorList,
  90. backgroundColor: '#fff',
  91. });
  92. }
  93. async function getList() {
  94. const res = await workType({});
  95. let zhStr = {
  96. "4dkk": '三维场景', //四维看看作品
  97. "mix": '综合作品', // 混合作品
  98. "pano": '全景图' //全景看看作品
  99. }
  100. pieData.value = res.map(ele => {
  101. return {
  102. ...ele,
  103. value: ele.count,
  104. name: zhStr[ele.groupKey],
  105. }
  106. })
  107. handlesetOptions();
  108. }
  109. onMounted(() => {
  110. getList();
  111. });
  112. </script>
  113. <style lang="less" scoped>
  114. .piechart {
  115. width: 100%;
  116. height: 100%;
  117. }
  118. </style>