Pie.vue 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. <template>
  2. <div ref="chartRef" :style="{ height, width }"></div>
  3. </template>
  4. <script lang="ts">
  5. import { defineComponent, PropType, ref, Ref, onMounted } from 'vue';
  6. import { useECharts } from '/@/hooks/web/useECharts';
  7. export default defineComponent({
  8. props: {
  9. width: {
  10. type: String as PropType<string>,
  11. default: '100%',
  12. },
  13. height: {
  14. type: String as PropType<string>,
  15. default: 'calc(100vh - 78px)',
  16. },
  17. },
  18. setup() {
  19. const chartRef = ref<HTMLDivElement | null>(null);
  20. const { setOptions } = useECharts(chartRef as Ref<HTMLDivElement>);
  21. const dataAll = [389, 259, 262, 324, 232, 176, 196, 214, 133, 370];
  22. const yAxisData = ['原因1', '原因2', '原因3', '原因4', '原因5', '原因6', '原因7', '原因8', '原因9', '原因10'];
  23. onMounted(() => {
  24. setOptions({
  25. backgroundColor: '#0f375f',
  26. title: [
  27. {
  28. text: '各渠道投诉占比',
  29. left: '2%',
  30. top: '1%',
  31. textStyle: {
  32. color: '#fff',
  33. fontSize: 14,
  34. },
  35. },
  36. {
  37. text: '投诉原因TOP10',
  38. left: '40%',
  39. top: '1%',
  40. textStyle: {
  41. color: '#fff',
  42. fontSize: 14,
  43. },
  44. },
  45. {
  46. text: '各级别投诉占比',
  47. left: '2%',
  48. top: '50%',
  49. textStyle: {
  50. color: '#fff',
  51. fontSize: 14,
  52. },
  53. },
  54. ],
  55. grid: [{ left: '50%', top: '7%', width: '45%', height: '90%' }],
  56. tooltip: {
  57. formatter: '{b} ({c})',
  58. },
  59. xAxis: [
  60. {
  61. gridIndex: 0,
  62. axisTick: { show: false },
  63. axisLabel: { show: false },
  64. splitLine: { show: false },
  65. axisLine: { show: false },
  66. },
  67. ],
  68. yAxis: [
  69. {
  70. gridIndex: 0,
  71. interval: 0,
  72. data: yAxisData.reverse(),
  73. axisTick: { show: false },
  74. axisLabel: { show: true },
  75. splitLine: { show: false },
  76. axisLine: { show: true, lineStyle: { color: '#6173a3' } },
  77. },
  78. ],
  79. series: [
  80. {
  81. name: '各渠道投诉占比',
  82. type: 'pie',
  83. radius: '30%',
  84. center: ['22%', '25%'],
  85. data: [
  86. { value: 335, name: '客服电话' },
  87. { value: 310, name: '奥迪官网' },
  88. { value: 234, name: '媒体曝光' },
  89. { value: 135, name: '质检总局' },
  90. { value: 105, name: '其他' },
  91. ],
  92. labelLine: { show: false },
  93. label: {
  94. show: true,
  95. formatter: '{b} \n ({d}%)',
  96. color: '#B1B9D3',
  97. },
  98. },
  99. {
  100. name: '各级别投诉占比',
  101. type: 'pie',
  102. radius: '30%',
  103. center: ['22%', '75%'],
  104. labelLine: { show: false },
  105. data: [
  106. { value: 335, name: 'A级' },
  107. { value: 310, name: 'B级' },
  108. { value: 234, name: 'C级' },
  109. { value: 135, name: 'D级' },
  110. ],
  111. label: {
  112. show: true,
  113. formatter: '{b} \n ({d}%)',
  114. color: '#B1B9D3',
  115. },
  116. },
  117. {
  118. name: '投诉原因TOP10',
  119. type: 'bar',
  120. xAxisIndex: 0,
  121. yAxisIndex: 0,
  122. barWidth: '45%',
  123. itemStyle: { color: '#86c9f4' },
  124. label: { show: true, position: 'right', color: '#9EA7C4' },
  125. data: dataAll.sort(),
  126. },
  127. ],
  128. });
  129. });
  130. return { chartRef };
  131. },
  132. });
  133. </script>