map3Data.vue 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. <template>
  2. <div style="width:800px;height:600px" ref="chartsDOM"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. import GetShandong from "@api/GetShandong";
  7. import shandong from "@views/tj/shandong.json"
  8. export default {
  9. name: "mapData",
  10. data() {
  11. return {
  12. resdata: [],
  13. yData:[],
  14. barData:[],
  15. centerData:{} ,
  16. myChart:null,
  17. visible:false
  18. }
  19. },
  20. mounted() {
  21. },
  22. watch: {
  23. resultMapData() {
  24. this.$nextTick(function () {
  25. for (var i = 0; i < 10; i++) {
  26. this.barData.push(this.resultMapData[i]);
  27. this.yData.push(i + this.resultMapData[i].name);
  28. }
  29. this.getPie()
  30. })
  31. },
  32. },
  33. created() {
  34. var arr = shandong.features
  35. arr.length>0 && arr.forEach((item,index) =>{
  36. var obj = {}
  37. this.centerData[item.properties.name] = item.properties.center
  38. })
  39. },
  40. props: {
  41. resultMapData: {
  42. type: Array,
  43. default: [{name: '济南市', value: 496, ssqy: 200, szdw: 296},
  44. {name: '青岛市', value: 66, ssqy: 200, szdw: 296},
  45. {name: '烟台市', value: 222, ssqy: 200, szdw: 296},
  46. {name: '潍坊市', value: 688, ssqy: 200, szdw: 296},
  47. {name: '菏泽市', value: 75, ssqy: 200, szdw: 296},
  48. {name: '日照市', value: 121, ssqy: 200, szdw: 296},
  49. {name: '威海市', value: 91, ssqy: 200, szdw: 296},
  50. {name: '枣庄市', value: 479, ssqy: 200, szdw: 296},
  51. {name: '临沂市', value: 34, ssqy: 200, szdw: 296},
  52. {name: '滨州市', value: 631, ssqy: 200, szdw: 296},
  53. {name: '东营市', value: 400, ssqy: 200, szdw: 296},
  54. {name: '淄博市', value: 988, ssqy: 200, szdw: 296},
  55. {name: '泰安市', value: 693, ssqy: 200, szdw: 296},
  56. {name: '聊城市', value: 934, ssqy: 200, szdw: 296},
  57. {name: '济宁市', value: 748, ssqy: 200, szdw: 296},
  58. {name: '德州市', value: 900, ssqy: 200, szdw: 296},]
  59. },
  60. titles:{
  61. type: String,
  62. }
  63. },
  64. methods: {
  65. getPie() {
  66. var _this = this
  67. var myChart = echarts.init(this.$refs["chartsDOM"]);
  68. // 显示 loading 动画
  69. myChart.showLoading();
  70. myChart.on("click", (params) => {
  71. _this.$emit('visible',{xzqh:params.data.xzqhdm});
  72. })
  73. // 再得到数据的基础上,进行地图绘制
  74. // 得到结果后,关闭动画
  75. myChart.hideLoading();
  76. // 注册地图(数据放在axios返回对象的data中哦)
  77. echarts.registerMap('SD', shandong);
  78. var options = {
  79. title: [{
  80. show: true,
  81. text: this.titles,
  82. }],
  83. tooltip: {
  84. triggerOn: "mousemove", //mousemove、click
  85. padding:8,
  86. borderWidth:1,
  87. borderColor:'#409eff',
  88. backgroundColor:'rgba(255,255,255,0.7)',
  89. formatter: function (params) {
  90. return params.name + ':' + '</br>' + "地块数量:" + params.value + '块' + '</br>'+"实际占用总面积:"+params.data.value2.toFixed(2)+"亩"
  91. },
  92. },
  93. visualMap: {
  94. type: 'continuous',
  95. orient: 'horizontal',
  96. itemWidth: 10,
  97. itemHeight: 80,
  98. text: ['高', '低'],
  99. showLabel: true,
  100. seriesIndex: [0],
  101. min: 0,
  102. max: 1500,
  103. inRange: {
  104. color: ['#ccdaeb', '#50afe4', '#308ae3'] // 渐变颜色
  105. },
  106. textStyle: {
  107. color: '#7B93A7'
  108. },
  109. bottom: 30,
  110. left: 'left',
  111. },
  112. geo: {
  113. roam: false,
  114. map: 'SD',
  115. // layoutSize: '80%',
  116. label: {
  117. normal: {
  118. show: false, //显示省份标签
  119. },
  120. emphasis: { //对应的鼠标悬浮效果
  121. show: false,
  122. textStyle: {
  123. color: "#000"
  124. }
  125. }
  126. },
  127. itemStyle: {
  128. emphasis: {
  129. areaColor: '#fff464'
  130. }
  131. }
  132. },
  133. series: [{
  134. name: 'mapSer',
  135. type: 'map',
  136. roam: false,
  137. geoIndex: 0,
  138. data: this.resultMapData
  139. }]
  140. };
  141. myChart.clear();
  142. myChart.setOption(options , true);
  143. myChart.resize();
  144. //地图的点击事件
  145. myChart.on('click', function(params) {
  146. })
  147. var option = {
  148. xAxis: [],
  149. yAxis: [],
  150. grid: [],
  151. series: [],
  152. };
  153. echarts.util.each(_this.resultMapData, function(dataItem, idx) {
  154. debugger
  155. var geoCoord = _this.centerData[dataItem.name];
  156. var coord =myChart.convertToPixel('geo', geoCoord);
  157. idx += '';
  158. var inflationData = [dataItem.value];
  159. option.xAxis.push({
  160. id: idx,
  161. gridId: idx,
  162. type: 'category',
  163. nameLocation: 'middle',
  164. name:dataItem.name,
  165. nameGap: 3,
  166. nameTextStyle:{
  167. color:"#000000",
  168. },
  169. splitLine: {
  170. show: false
  171. },
  172. axisTick: {
  173. show: false
  174. },
  175. axisLabel: {
  176. color:"#fff",
  177. show: false
  178. },
  179. axisLine: {
  180. onZero: false,
  181. lineStyle: {
  182. color: '#555'
  183. }
  184. },
  185. data: ["地块数量"],
  186. z: 100
  187. });
  188. option.yAxis.push({
  189. id: idx,
  190. gridId: idx,
  191. splitLine: {
  192. show: false
  193. },
  194. axisTick: {
  195. show: false
  196. },
  197. axisLabel: {
  198. show: false
  199. },
  200. axisLine: {
  201. show: false,
  202. lineStyle: {
  203. color: '#fff'
  204. }
  205. },
  206. z: 100
  207. });
  208. option.grid.push({
  209. id: idx,
  210. width: 15,
  211. height: 20,
  212. left: coord[0]-15,
  213. top: coord[1] -15,
  214. z: 100
  215. });
  216. option.series.push({
  217. id: idx,
  218. type: 'bar',
  219. xAxisId: idx,
  220. yAxisId: idx,
  221. barGap: 0,
  222. barCategoryGap: 2,
  223. data: inflationData,
  224. label: {
  225. normal: {
  226. show: true,//开启显示
  227. position: 'top',//柱形上方
  228. textStyle: { //数值样式
  229. color: '#494848'
  230. }
  231. }},
  232. z: 100,
  233. itemStyle: {
  234. normal: {
  235. color: function(params){
  236. // 柱状图每根柱子颜色
  237. var colorList = ['#3553d5','#ff0404'];//['#fcae91','#fb6a4a','#cb181d'];
  238. return colorList[params.dataIndex];
  239. }
  240. }
  241. }
  242. });
  243. })
  244. myChart.setOption(option);
  245. },
  246. }
  247. // mounted() {
  248. // this.getPie()
  249. // },
  250. }
  251. </script>
  252. <style scoped>
  253. </style>