CityRank.vue 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. <template>
  2. <div class="wrap-container sn-container" id="cityrank">
  3. <div class="sn-content">
  4. <div class="sn-title">柱状图</div>
  5. <div class="sn-body">
  6. <div class="wrap-container">
  7. <div class="chart" id="chart_left1"></div>
  8. </div>
  9. </div>
  10. </div>
  11. </div>
  12. </template>
  13. <script>
  14. import screenfull from "screenfull";
  15. export default {
  16. name: "CityRank",
  17. data() {
  18. return {
  19. fullscreen: false
  20. }
  21. },
  22. mounted() {
  23. this.getEchartLeft1();
  24. },
  25. methods: {
  26. getEchartLeft1() {
  27. // 实例化对象
  28. let myChart = echarts.init(document.getElementById('chart_left1'));
  29. let charts = { // 按顺序排列从大到小
  30. cityList: ['湖北', '香港', '广东', '湖南', '四川', '浙江', '上海'],
  31. cityData: [68149, 8300, 2035, 1020, 843, 1300, 1473],
  32. function(p) {
  33. return p.name + ":" + this.cityData(p.value);
  34. }
  35. }
  36. let top10CityList = charts.cityList;
  37. let top10CityData = charts.cityData;
  38. let color = ['rgba(14,109,236', 'rgba(255,91,6', 'rgba(100,255,249', 'rgba(248,195,248', 'rgba(110,234,19', 'rgba(255,168,17', 'rgba(218,111,227'];
  39. let lineY = [];
  40. for (let i = 0; i < charts.cityList.length; i++) {
  41. let x = i
  42. if (x > color.length - 1) {
  43. x = color.length - 1
  44. }
  45. let data = {
  46. name: charts.cityList[i],
  47. color: color[x] + ')',
  48. value: top10CityData[i],
  49. itemStyle: {
  50. normal: {
  51. show: true,
  52. color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
  53. offset: 0,
  54. color: color[x] + ', 0.3)'
  55. }, {
  56. offset: 1,
  57. color: color[x] + ', 1)'
  58. }], false),
  59. barBorderRadius: 10
  60. },
  61. emphasis: {
  62. shadowBlur: 15,
  63. shadowColor: 'rgba(0, 0, 0, 0.1)'
  64. }
  65. }
  66. }
  67. lineY.push(data)
  68. }
  69. // 指定配置和数据
  70. let option = {
  71. toolbox: {
  72. feature: {
  73. mytool: {
  74. show: true,
  75. title: "全屏",
  76. icon: 'path://M181 357.5V181.2h176.4c14.3 0 25.9-11.6 25.9-25.9v-31.1c0-14.3-11.6-25.9-25.9-25.9H118c-11 0-20 9-20 20v239.4c0 14.3 11.6 25.9 25.9 25.9H155c14.4-0.1 26-11.7 26-26.1zM668.6 181.2H845v176.4c0 14.3 11.6 25.9 25.9 25.9H902c14.3 0 25.9-11.6 25.9-25.9V118.2c0-11-9-20-20-20H668.6c-14.3 0-25.9 11.6-25.9 25.9v31.1c0 14.3 11.6 26 25.9 26zM357.4 845.2H181V668.8c0-14.3-11.6-25.9-25.9-25.9H124c-14.3 0-25.9 11.6-25.9 25.9v239.4c0 11 9 20 20 20h239.4c14.3 0 25.9-11.6 25.9-25.9v-31.1c-0.1-14.4-11.7-26-26-26zM845 668.8v176.4H668.6c-14.3 0-25.9 11.6-25.9 25.9v31.1c0 14.3 11.6 25.9 25.9 25.9H908c11 0 20-9 20-20V668.8c0-14.3-11.6-25.9-25.9-25.9H871c-14.4 0-26 11.6-26 25.9z',
  77. onclick: function () {
  78. const element = document.getElementById('chart_left1');
  79. if (!screenfull.isEnabled) {//判断是否支持全屏
  80. this.$message({
  81. message: '您的浏览器暂时不支持全屏切换',
  82. type: 'warning'
  83. })
  84. return false
  85. }
  86. screenfull.toggle(element)
  87. },
  88. }
  89. },
  90. },
  91. color: color,
  92. tooltip: {
  93. trigger: 'item',
  94. },
  95. grid: {
  96. borderWidth: 0,
  97. top: '5%',
  98. left: '2%',
  99. right: '2%',
  100. bottom: '0%',
  101. containLabel: true
  102. },
  103. xAxis: [{
  104. type: 'value',
  105. axisTick: {
  106. show: false
  107. },
  108. axisLine: {
  109. show: false
  110. },
  111. splitLine: {
  112. show: false
  113. },
  114. axisLabel: {
  115. show: false
  116. }
  117. }],
  118. yAxis: [{
  119. type: 'category',
  120. inverse: true,
  121. axisTick: {
  122. show: false
  123. },
  124. axisLine: {
  125. show: false
  126. },
  127. axisLabel: {
  128. show: true,
  129. inside: false,
  130. textStyle: {
  131. color: '#b3ccf8',
  132. fontSize: 13
  133. },
  134. },
  135. data: top10CityList
  136. }, {
  137. type: 'category',
  138. axisLine: {
  139. show: false
  140. },
  141. axisTick: {
  142. show: false
  143. },
  144. axisLabel: {
  145. show: true,
  146. inside: false,
  147. textStyle: {
  148. color: '#b3ccf8',
  149. fontSize: 13
  150. },
  151. formatter: (val) => {
  152. return `${val}`
  153. }
  154. },
  155. splitArea: {
  156. show: false
  157. },
  158. splitLine: {
  159. show: false
  160. },
  161. data: top10CityData.reverse()
  162. }],
  163. series: [{
  164. name: '',
  165. type: 'bar',
  166. zlevel: 2,
  167. barWidth: '10px',
  168. data: lineY,
  169. animationDuration: 1500,
  170. label: {
  171. normal: {
  172. color: '#b3ccf8',
  173. show: false,
  174. position: [0, '-15px'],
  175. textStyle: {
  176. fontSize: 13
  177. },
  178. formatter: (a, b) => {
  179. return a.name;
  180. }
  181. }
  182. }
  183. }]
  184. };
  185. // 把配置给实例对象
  186. myChart.setOption(option, true);
  187. window.addEventListener('resize', () => {
  188. myChart.resize();
  189. });
  190. },
  191. },
  192. beforeDestroy() {
  193. }
  194. };
  195. </script>
  196. <style lang="scss" scoped>
  197. .sn-container {
  198. width: 99%;
  199. height: 99%;
  200. .chart {
  201. height: 99%;
  202. width: 99%;
  203. //margin-bottom: 4%;
  204. margin-right: 1%;
  205. }
  206. }
  207. </style>