chart-gridStaff.vue 3.9 KB

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