3.vue 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div id="qwe" style="width: 100%; height: 100%; "></div>
  3. </template>
  4. <script>
  5. import { oldPersonSelectByJob } from '../../api'
  6. import 'echarts-liquidfill'
  7. export default {
  8. name: "PatrolmanJobDistributionCount",
  9. data() {
  10. return {
  11. dataArr: [],
  12. colorArr: [
  13. { color1: '#00D7FF', color2: '#00D7FF' },
  14. { color1: '#E9F82D', color2: '#E9F82D' },
  15. { color1: '#32FC6B', color2: '#32FC6B' },
  16. { color1: '#FEC400', color2: '#FEC400' }
  17. ]
  18. }
  19. },
  20. methods: {
  21. async draw() {
  22. const result = await oldPersonSelectByJob({}, 'POST');
  23. this.dataArr = result;
  24. const seriesArr = [];
  25. const titleArr = [];
  26. for(let i = 0; i < this.dataArr.length; i++) {
  27. const d = this.dataArr[i];
  28. seriesArr.push({
  29. type: 'liquidFill',
  30. data: [`${(parseInt(d.value) / 100).toFixed(2)}`],
  31. radius: '40%',
  32. center: [`${ 12.5 + i * 25 }%`, `40%`],
  33. backgroundStyle: {
  34. borderColor: this.colorArr[i].color1,
  35. color: "#011065"
  36. },
  37. outline: {
  38. show: false
  39. },
  40. waveAnimation: false, // 禁止左右波动
  41. label: {
  42. normal: {
  43. position: ['50%', '50%'],
  44. textStyle: {
  45. fontSize: this.fontSize(0.2),
  46. color: this.colorArr[i].color1
  47. },
  48. formatter: `${ d.value }`
  49. }
  50. },
  51. itemStyle: {
  52. normal: {
  53. color: new this.$echarts.graphic.LinearGradient(
  54. 0, 0, 0, 1,
  55. [
  56. {offset: 0, color: this.colorArr[i].color1},
  57. {offset: 1, color: this.colorArr[i].color2}
  58. ]
  59. )
  60. }
  61. }
  62. });
  63. titleArr.push({
  64. text: d.label,
  65. left: `${ 12.5 + i * 25 }%`,
  66. top: `70%`,
  67. textAlign: "center",
  68. textStyle: {
  69. fontSize: this.fontSize(0.18),
  70. fontWeight: 'normal',
  71. color: '#fff'
  72. }
  73. });
  74. }
  75. let myChart = this.$echarts.init(document.getElementById('qwe'));
  76. myChart.setOption({
  77. title: titleArr,
  78. xAxis: {
  79. type: 'value',
  80. max: 100,
  81. splitLine: {
  82. show: false
  83. },
  84. axisLine: {
  85. show: false
  86. },
  87. axisLabel: {
  88. show: false
  89. },
  90. axisTick: {
  91. show: false
  92. }
  93. },
  94. yAxis: {
  95. type: 'category',
  96. splitLine: {
  97. show: false
  98. },
  99. axisLine: {
  100. show: false
  101. },
  102. axisLabel: {
  103. show: false
  104. },
  105. axisTick: {
  106. show: false
  107. }
  108. },
  109. series: seriesArr
  110. });
  111. },
  112. fontSize(res) {
  113. let clientWidth = window.innerWidth || document.documentElement.clientWidth || document.body.clientWidth;
  114. if (!clientWidth) return;
  115. let fontSize = 100 * (clientWidth / 1920);
  116. return res * fontSize;
  117. }
  118. },
  119. watch: {
  120. data() {
  121. this.myChart.destroy();
  122. this.draw();
  123. }
  124. },
  125. mounted() {
  126. this.draw();
  127. }
  128. }
  129. </script>
  130. <style scoped>
  131. </style>