chart-gridStaff.vue 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <!-- **************************************NO.13 消火栓*************************************** -->
  2. <template>
  3. <div class="chart-container">
  4. <div id="hydrant" style="width: 100%; height:55vh;">
  5. </div>
  6. </div>
  7. </template>
  8. <script>
  9. import * as echarts from 'echarts';
  10. import {getWgry} from '@/api/bigdata.js'
  11. export default {
  12. name: 'hydrant',
  13. data() {
  14. return {
  15. count: 0,
  16. getWgry: []
  17. }
  18. },
  19. mounted() {
  20. this.zzz()
  21. },
  22. methods: {
  23. zzz() {
  24. setTimeout(() => {
  25. let that = this
  26. getWgry().then(resp => {
  27. that.getWgry = Array.isArray(resp.data) && resp.data.length > 20 ? resp.data.splice(0,20) : resp.data
  28. // alert("网格人员")
  29. that.myEcharts()
  30. })
  31. }, 1000)
  32. },
  33. // 出处 http://192.144.199.210:8080/editor/index.html?chart_id=Ve9zCnhVwZvXTdD0
  34. myEcharts() {
  35. let that = this
  36. var chartDom = document.getElementById('hydrant');
  37. var myChart = echarts.init(chartDom);
  38. function rand(m, n) {
  39. if (!n) {
  40. return Math.floor(Math.random() * m);
  41. } else {
  42. var c = n - m + 1;
  43. return Math.floor(Math.random() * c + m);
  44. }
  45. }
  46. function getMax(arr, key) {
  47. var max = 0,
  48. len = arr.length;
  49. for (var i = 0; i < len; i++) {
  50. var item = arr[i][key];
  51. if (max < item) max = item;
  52. }
  53. return max;
  54. }
  55. function getValArr(arr, key) {
  56. var val = [],
  57. len = arr.length;
  58. for (var i = 0; i < len; i++) {
  59. val.push(arr[i][key]);
  60. }
  61. return val;
  62. }
  63. var arr = that.getWgry
  64. // for (var i = 0; i < 10; i++) {
  65. // arr.push({
  66. // name: '类目名称' + rand(99),
  67. // amount: rand(99999) / 100 // 采购金额
  68. // });
  69. // }
  70. var max = getMax(arr, 'value'),
  71. angleAxisData = getValArr(arr, 'name');
  72. $.each(arr, function (i, e) {
  73. e.value = (e.value / max * 100).toFixed(2);
  74. });
  75. var option = {
  76. backgroundColor: '#222',
  77. tooltip: {
  78. trigger: 'item',
  79. textStyle: {
  80. fontSize: 16,
  81. color: '#fff',
  82. fontFamily: 'Microsoft YaHei'
  83. }
  84. },
  85. angleAxis: {
  86. type: 'category',
  87. axisLine: {
  88. lineStyle: {
  89. color: '#6d8a92'
  90. }
  91. },
  92. axisLabel: {
  93. interval: 0,
  94. fontSize: 14,
  95. color: '#fff',
  96. fontFamily: 'Microsoft YaHei'
  97. },
  98. axisTick: {
  99. show: false
  100. },
  101. data: angleAxisData,
  102. z: 10
  103. },
  104. radiusAxis: {
  105. max: 100,
  106. min: 0,
  107. axisTick: {
  108. show: false
  109. },
  110. axisLine: {
  111. show: true,
  112. lineStyle: {
  113. color: '#6d8a92'
  114. }
  115. },
  116. axisLabel: {
  117. formatter: '{value}%',
  118. textStyle: {
  119. fontSize: 11,
  120. color: '#61d9fb',
  121. fontFamily: 'Microsoft YaHei'
  122. }
  123. },
  124. splitLine: {
  125. show: true,
  126. lineStyle: {
  127. color: '#6d8a92'
  128. }
  129. },
  130. splitArea: {
  131. areaStyle: {
  132. color: 'transparent'
  133. }
  134. }
  135. },
  136. polar: {
  137. center: ['50%', '50%'],
  138. radius: '74%',
  139. },
  140. series: [{
  141. type: 'bar',
  142. data: arr,
  143. itemStyle: {
  144. color: function (params) {
  145. var colorList = ['#5cc6ca', '#d87a7f', '#f5b97f', '#5ab1ef', '#b6a2de', '#8d98b3', '#e5d02d', '#97b552', '#956f6d', '#d0579c'];
  146. return colorList[params.dataIndex];
  147. }
  148. },
  149. coordinateSystem: 'polar',
  150. }]
  151. };
  152. option && myChart.setOption(option);
  153. },
  154. },
  155. }
  156. </script>
  157. <style rel="stylesheet/scss" lang="scss" scoped>
  158. .chart-container {
  159. width: 100%;
  160. height: auto;
  161. position: relative;
  162. padding-bottom: 10px;
  163. display: flex;
  164. }
  165. </style>