1.vue 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  1. <template>
  2. <div id="myChart" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. import { oldPersonSelectUserBySex } from '../../api'
  6. export default {
  7. //巡防员性别分布统计
  8. name: "PatrolmanSexCount",
  9. data() {
  10. return {
  11. dataArr: [],
  12. colorArr: ['rgba(0, 227,255, 1)', 'rgba(253, 200, 1, 1)'],
  13. myChart: null
  14. }
  15. },
  16. methods: {
  17. async draw() {
  18. const result = await oldPersonSelectUserBySex({}, 'POST');
  19. this.dataArr = result;
  20. const seriesArr = [];
  21. const titleArr = [];
  22. for (let i = 0; i < this.dataArr.length; i++) {
  23. const d = this.dataArr[i];
  24. titleArr.push({
  25. text: d.label,
  26. left: "12%",
  27. top: `${i == 0 ? 13 : 55}%`,
  28. textAlign: "center",
  29. textStyle: {
  30. fontSize: "16",
  31. fontWeight: 'normal',
  32. color: "#fff"
  33. }
  34. });
  35. titleArr.push({
  36. text: `${d.percent}%`,
  37. left: "68%",
  38. top: `${i == 0 ? 13 : 55}%`,
  39. textAlign: "center",
  40. textStyle: {
  41. fontSize: "20",
  42. fontWeight: 'normal',
  43. color: this.colorArr[i]
  44. }
  45. });
  46. const borderArr = new Array(this.dataArr.length).fill({});
  47. borderArr[i] = {value: 317, symbolPosition: 'start'};
  48. seriesArr.push({
  49. type: 'pictorialBar',
  50. symbol: `image://${require('../../assets/PatrolmanStatistics/border.png')}`,
  51. symbolSize: [317, 47],
  52. symbolOffset: [0, 0],
  53. data: borderArr,
  54. label: {
  55. show: true,
  56. position: 'right',
  57. offset: [-120, 0],
  58. color: this.colorArr[this.colorArr.length - 1 - i],
  59. fontSize: 20,
  60. fontWeight: 'bold',
  61. formatter: () => {
  62. return `${d.value}人`;
  63. }
  64. },
  65. z: 1
  66. });
  67. const step = (Math.floor(parseInt(d.percent) / 10) < 1 ? 1 : Math.floor(parseInt(d.percent) / 10));
  68. for (let j = 0; j < 10; j++) {
  69. const blockArr = new Array(this.dataArr.length).fill({});
  70. blockArr[this.dataArr.length - 1 - i] = {value: 317, symbolPosition: 'start'};
  71. let symbolImage = `image://${require('../../assets/PatrolmanStatistics/sex-default.png')}`;
  72. if (j < step) {
  73. if (i == 0) {
  74. symbolImage = `image://${require('../../assets/PatrolmanStatistics/sex-male.png')}`;
  75. } else {
  76. symbolImage = `image://${require('../../assets/PatrolmanStatistics/sex-female.png')}`;
  77. }
  78. }
  79. seriesArr.push({
  80. type: 'pictorialBar',
  81. symbol: symbolImage,
  82. symbolSize: [19, 37],
  83. symbolOffset: [10 + j * 31, 0],
  84. data: blockArr,
  85. z: 2
  86. });
  87. }
  88. }
  89. this.myChart = this.$echarts.init(document.getElementById('myChart'));
  90. this.myChart.setOption({
  91. title: titleArr,
  92. grid: {
  93. left: "2%",
  94. right: "2%",
  95. top: "16%",
  96. bottom: "2%",
  97. },
  98. xAxis: {
  99. max: 300,
  100. splitLine: {
  101. show: false
  102. },
  103. axisLine: {
  104. show: false
  105. },
  106. axisLabel: {
  107. show: false
  108. },
  109. axisTick: {
  110. show: false
  111. }
  112. },
  113. yAxis: {
  114. type: 'category',
  115. splitLine: {
  116. show: false
  117. },
  118. axisLine: {
  119. show: false
  120. },
  121. axisLabel: {
  122. show: false
  123. },
  124. axisTick: {
  125. show: false
  126. }
  127. },
  128. series: seriesArr
  129. });
  130. }
  131. },
  132. watch: {
  133. data() {
  134. this.myChart.destroy();
  135. this.draw();
  136. }
  137. },
  138. mounted() {
  139. this.draw();
  140. }
  141. }
  142. </script>
  143. <style scoped>
  144. </style>