2.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <template>
  2. <div id="ww" style="width: 100%; height: 100%;"></div>
  3. </template>
  4. <script>
  5. import { oldPersonSelectAuthAndLook } from '../../api'
  6. export default {
  7. name: "PatrolmanAuthenticationCount",
  8. data() {
  9. return {
  10. // dataArr: [
  11. // { label: '党员', arr: [ { label: '认证', value: 1234 }, { label: '未认证', value: 4321 } ] },
  12. // { label: '群众', arr: [ { label: '认证', value: 4567 }, { label: '未认证', value: 7654 } ] }
  13. // ],
  14. dataArr: [],
  15. colorArr: [
  16. { color1: '#FFA625', color2: '#FFD09C' },
  17. { color1: '#00FF0C', color2: '#B7FFE2' }
  18. ],
  19. myChart: null
  20. }
  21. },
  22. methods: {
  23. async draw() {
  24. const result = await oldPersonSelectAuthAndLook({}, 'POST');
  25. this.dataArr = result;
  26. const seriesArr = [];
  27. let maxValue = 0;
  28. for(let i = 0; i < this.dataArr.length; i++) {
  29. const d = this.dataArr[i];
  30. const arr = d.arr;
  31. for(let j = 0; j < arr.length; j++) {
  32. if(maxValue < arr[j].value) {
  33. maxValue = arr[j].value;
  34. }
  35. }
  36. }
  37. const labelArr = this.dataArr[0].arr.map((item) => item.label).reverse();
  38. for(let i = 0; i < this.dataArr.length; i++) {
  39. const d = this.dataArr[i];
  40. seriesArr.push({
  41. name: d.label,
  42. type: 'bar',
  43. barWidth: '20%',
  44. data: [
  45. {
  46. value: d.arr[1].value,
  47. itemStyle: {
  48. normal: {
  49. color: new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  50. offset: 0,
  51. color: this.colorArr[i].color1
  52. }, {
  53. offset: 1,
  54. color: this.colorArr[i].color2
  55. }]),
  56. barBorderRadius: [0, 50, 50, 0]
  57. }
  58. },
  59. label: {
  60. show: true,
  61. position: 'right',
  62. color: this.colorArr[i].color1,
  63. fontSize: 20
  64. },
  65. },
  66. {
  67. value: d.arr[0].value,
  68. itemStyle: {
  69. normal: {
  70. color: new this.$echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  71. offset: 0,
  72. color: this.colorArr[i].color1
  73. }, {
  74. offset: 1,
  75. color: this.colorArr[i].color2
  76. }]),
  77. barBorderRadius: [0, 50, 50, 0]
  78. }
  79. },
  80. label: {
  81. show: true,
  82. position: 'right',
  83. color: this.colorArr[i].color1,
  84. fontSize: 20
  85. },
  86. }
  87. ]
  88. });
  89. const kkArr = new Array(this.dataArr.length).fill({});
  90. kkArr[i] = { value: 100, symbolPosition: 'start' };
  91. seriesArr.push({
  92. type: 'pictorialBar',
  93. symbol: `image://${require('../../assets/PatrolmanStatistics/label.png')}`,
  94. symbolSize: [16, 50],
  95. symbolOffset: [-20, 0],
  96. data: kkArr,
  97. label: {
  98. show: true,
  99. position: 'left',
  100. offset: [-30, 0],
  101. distance: 0,
  102. color: '#fff',
  103. fontSize: 16,
  104. formatter: `${ labelArr[i] }`
  105. },
  106. z: 10
  107. });
  108. }
  109. this.myChart = this.$echarts.init(document.getElementById('ww'));
  110. this.myChart.setOption({
  111. color: [this.colorArr[0].color1, this.colorArr[0].color1, this.colorArr[1].color1],
  112. legend: {
  113. data: ["党员", "群众"],
  114. right: '4%',
  115. top: '13%',
  116. textStyle: {
  117. color: "#fff"
  118. },
  119. },
  120. grid: {
  121. left: '20%',
  122. right: '15%',
  123. bottom: '10%',
  124. height: '80%',
  125. top:'20%',
  126. containLabel: true
  127. },
  128. xAxis: [
  129. {
  130. type: 'value',
  131. max: maxValue,
  132. axisTick: {
  133. show: false
  134. },
  135. axisLabel: {
  136. show: false
  137. },
  138. axisLine: {
  139. show: false
  140. },
  141. splitLine: {
  142. show: false
  143. }
  144. }
  145. ],
  146. yAxis: [
  147. {
  148. type: 'category',
  149. nameTextStyle: {
  150. show: false
  151. },
  152. axisLine: {
  153. show: false
  154. },
  155. axisLabel: {
  156. show: false
  157. },
  158. splitLine: {
  159. show: false
  160. }
  161. }
  162. ],
  163. series: seriesArr
  164. });
  165. }
  166. },
  167. watch: {
  168. data() {
  169. this.myChart.destroy();
  170. this.draw();
  171. }
  172. },
  173. mounted() {
  174. this.draw();
  175. }
  176. }
  177. </script>
  178. <style scoped>
  179. </style>