index.vue 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. <!--
  2. 描述: 金字塔趋势
  3. 作者: Jack Chen
  4. 日期: 2020-04-18
  5. -->
  6. <template>
  7. <div class="wrap-container sn-container">
  8. <div class="sn-content">
  9. <div class="sn-title">金字塔趋势</div>
  10. <div class="sn-body">
  11. <div class="wrap-container">
  12. <div class="chartsdom" id="chart_ptrend"></div>
  13. </div>
  14. </div>
  15. </div>
  16. </div>
  17. </template>
  18. <script>
  19. export default {
  20. name: "pyramidTrend",
  21. data() {
  22. return {
  23. option: null,
  24. dataMap: {}
  25. }
  26. },
  27. mounted() {
  28. this.getEchart();
  29. },
  30. methods: {
  31. dataFormatter(obj) {
  32. let pList = ['长沙','湘潭','株洲','岳阳','邵阳','衡阳','益阳','娄底','怀化','湘西','张家界','郴州','常德','永州'];
  33. let temp;
  34. for (let x = 0; x < 3; x++) {
  35. let max = 0;
  36. let sum = 0;
  37. temp = obj[x];
  38. for (let i = 0, l = temp.length; i < l; i++) {
  39. max = Math.max(max, temp[i]);
  40. sum += temp[i];
  41. obj[x][i] = {
  42. name: pList[i],
  43. value: temp[i]
  44. };
  45. }
  46. obj[x + 'max'] = Math.floor(max / 100) * 100;
  47. obj[x + 'sum'] = sum;
  48. }
  49. return obj;
  50. },
  51. getEchart() {
  52. let myChart = echarts.init(document.getElementById('chart_ptrend'));
  53. let itemStyle = {
  54. barBorderRadius: [15, 0],
  55. color: '#0084ff'
  56. }
  57. this.dataMap.dataType = this.dataFormatter({
  58. 2:[124,145,261,54,195,131,150,39,11,40,23,51,45,88],
  59. 1:[136,159,205,41,306,7,77,101,24,34,8,15,14,9],
  60. 0:[118,128,220,47,92,14,9,11,113,61,11,22,33,5],
  61. });
  62. this.option = {
  63. baseOption: {
  64. timeline: {
  65. axisType: 'category',
  66. autoPlay: true,
  67. playInterval: 1000,
  68. data: ['一类', '二类', '三类'],
  69. left: 80,
  70. right: 80,
  71. bottom: 10,
  72. lineStyle: {
  73. color: '#179bf1'
  74. },
  75. label: {
  76. color: '#fff'
  77. },
  78. checkpointStyle: {
  79. color: '#01d8ff',
  80. symbolSize: 10,
  81. borderColor: 'rgba(1, 216, 255, 0.5)',
  82. borderWidth: 5,
  83. },
  84. controlStyle: {
  85. show: false,
  86. },
  87. itemStyle: {
  88. borderColor: '#004b85',
  89. borderWidth: 1,
  90. shadowColor: 'rgba(1, 216, 225, 0.5)',
  91. shadowBlur: 5
  92. },
  93. emphasis: {
  94. label: {
  95. color: '#01d8ff',
  96. show: false
  97. },
  98. checkpointStyle: {
  99. color: '#01d8ff',
  100. borderColor: 'rgba(1, 216, 255, 0.5)',
  101. borderWidth: 5,
  102. },
  103. itemStyle: {
  104. color: '#01d8ff',
  105. borderColor: 'rgba(1, 216, 225, 0.5)',
  106. borderWidth: 5
  107. }
  108. }
  109. },
  110. calculable: true,
  111. grid: {
  112. top: '10%',
  113. bottom: '25%'
  114. },
  115. xAxis: [{
  116. type: 'category',
  117. axisLabel: {
  118. interval: 0
  119. },
  120. data: ['长沙','湘潭','株洲','岳阳','邵阳','衡阳','益阳','娄底','怀化','湘西','张家界','郴州','常德','永州'],
  121. splitLine: {
  122. show: false
  123. },
  124. axisTick: {
  125. show: false
  126. },
  127. axisLine: {
  128. show: true,
  129. lineStyle: {
  130. color: '#2867a8',
  131. }
  132. },
  133. }],
  134. yAxis: [{
  135. type: 'value',
  136. name: '家',
  137. splitLine: {
  138. show: false
  139. },
  140. axisTick: {
  141. show: false
  142. },
  143. axisLine: {
  144. show: true,
  145. lineStyle: {
  146. color: '#2867a8'
  147. }
  148. }
  149. }],
  150. series: [{
  151. name: '一类',
  152. type: 'bar',
  153. barWidth: 15,
  154. legendHoverLink: true,
  155. label: {
  156. show: true,
  157. position: 'top',
  158. color: '#fff'
  159. },
  160. }]
  161. },
  162. options: [{
  163. series: [{
  164. data: this.dataMap.dataType['0'],
  165. itemStyle: itemStyle
  166. }]
  167. },{
  168. series: [{
  169. data: this.dataMap.dataType['1'],
  170. itemStyle: itemStyle
  171. }]
  172. },{
  173. series: [{
  174. data: this.dataMap.dataType['2'],
  175. itemStyle: itemStyle
  176. }]
  177. }]
  178. }
  179. myChart.setOption(this.option, true);
  180. window.addEventListener('resize', () => {
  181. myChart.resize();
  182. });
  183. }
  184. },
  185. beforeDestroy() {
  186. }
  187. };
  188. </script>
  189. <style lang="scss" scoped>
  190. .sn-container {
  191. left: 666px;
  192. top: 1548px;
  193. width: 586px;
  194. height: 400px;
  195. .chartsdom {
  196. width: 100%;
  197. height: 100%;
  198. }
  199. }
  200. </style>