echarts配置散点地图代码

x33g5p2x  于2021-12-08 转载在 Echarts  
字(2.9k)|赞(0)|评价(0)|浏览(539)


 

  1. <div id="myChart" :style="{ width: '70vh', height: '70vh' }"></div>
  2. import china from "echarts/map/json/china.json";
  3. init() {
  4. var myChart = this.$echarts.init(document.getElementById("myChart"));
  5. myChart.showLoading();
  6. var mapName = "china";
  7. var geoCoordMap = {};
  8. /* 获取地图数据 */
  9. var mapFeatures = china.features;
  10. mapFeatures.forEach(function (v) {
  11. // 地区名称
  12. var name = v.properties.name;
  13. // 地区经纬度
  14. geoCoordMap[name] = v.properties.center;
  15. });
  16. var max = 480,
  17. min = 9; // todo
  18. var maxSize4Pin = 100,
  19. minSize4Pin = 20;
  20. var convertData = function (data) {
  21. var res = [];
  22. for (var i = 0; i < data.length; i++) {
  23. var geoCoord = geoCoordMap[data[i].name];
  24. if (geoCoord) {
  25. res.push({
  26. name: data[i].name,
  27. value: geoCoord.concat(data[i].value),
  28. });
  29. }
  30. }
  31. return res;
  32. };
  33. var option = {
  34. visualMap: {
  35. show: true,
  36. min: 0,
  37. max: 1000,
  38. left: "left",
  39. top: "bottom",
  40. text: ["高", "低"], // 文本,默认为数值文本
  41. calculable: true,
  42. seriesIndex: [1],
  43. inRange: {
  44. color: ["#00467F", "#A5CC82"], // 蓝绿
  45. },
  46. },
  47. geo: {
  48. //坐标系为地理坐标系 geo
  49. show: true,
  50. map: mapName, //地图加散点
  51. label: {
  52. normal: {
  53. show: false,
  54. },
  55. emphasis: {
  56. show: false,
  57. },
  58. },
  59. roam: true,
  60. // 设置地图块的相关显示信息
  61. itemStyle: {
  62. normal: {
  63. // 普通状态下的样式
  64. areaColor: "#d1def3",
  65. borderColor: "#b4caef",
  66. borderWidth: 1,
  67. },
  68. emphasis: {
  69. // 高亮状态下的样式
  70. areaColor: "#9abfff", // hover效果
  71. },
  72. },
  73. },
  74. series: [
  75. {
  76. //新建散点图
  77. name: "散点",
  78. type: "scatter", //散点图 scatter
  79. coordinateSystem: "geo",
  80. data: this.data1, //定义图表数据内容的数组
  81. // symbolSize: function (val) {
  82. // return val[2] / 10;
  83. // },
  84. label: {
  85. normal: {
  86. formatter: "{b}",
  87. position: "right",
  88. show: true,
  89. },
  90. emphasis: {
  91. show: true,
  92. },
  93. },
  94. // 散点样式
  95. itemStyle: {
  96. normal: {
  97. color: "#F56C6C",
  98. },
  99. },
  100. },
  101. {
  102. type: "map",
  103. map: mapName,
  104. geoIndex: 0,
  105. aspectScale: 0.75, // 长宽比
  106. showLegendSymbol: false, // 存在legend时显示
  107. label: {
  108. normal: {
  109. show: true,
  110. },
  111. emphasis: {
  112. show: false,
  113. textStyle: {
  114. color: "#fff",
  115. },
  116. },
  117. },
  118. roam: true,
  119. itemStyle: {
  120. normal: {
  121. areaColor: "#031525",
  122. borderColor: "#3B5077",
  123. },
  124. emphasis: {
  125. areaColor: "#2B91B7",
  126. },
  127. },
  128. animation: false,
  129. data: this.data,
  130. },
  131. {
  132. name: "点",
  133. type: "scatter",
  134. coordinateSystem: "geo",
  135. symbol: "pin", // 气泡
  136. symbolSize: function (val) {
  137. var a = (maxSize4Pin - minSize4Pin) / (max - min);
  138. var b = minSize4Pin - a * min;
  139. b = maxSize4Pin - a * max;
  140. return a * val[2] + b;
  141. },
  142. label: {
  143. normal: {
  144. show: true,
  145. textStyle: {
  146. color: "#fff",
  147. fontSize: 9,
  148. },
  149. formatter: "{@[2]}",
  150. },
  151. },
  152. itemStyle: {
  153. normal: {
  154. color: "#F62157", // 标志颜色
  155. },
  156. },
  157. zlevel: 6,
  158. data: convertData(this.data),
  159. },
  160. {
  161. name: "Top 5",
  162. type: "effectScatter",
  163. coordinateSystem: "geo",
  164. data: convertData(
  165. this.data
  166. .sort(function (a, b) {
  167. return b.value - a.value;
  168. })
  169. .slice(0, 5)
  170. ),
  171. symbolSize: function (val) {
  172. return val[2] / 10;
  173. },
  174. showEffectOn: "render",
  175. rippleEffect: {
  176. brushType: "stroke",
  177. },
  178. hoverAnimation: true,
  179. label: {
  180. normal: {
  181. formatter: "{b}",
  182. position: "right",
  183. show: true,
  184. },
  185. },
  186. itemStyle: {
  187. normal: {
  188. color: "yellow",
  189. shadowBlur: 10,
  190. shadowColor: "yellow",
  191. },
  192. },
  193. zlevel: 1,
  194. },
  195. ],
  196. };
  197. myChart.setOption(option);
  198. myChart.hideLoading();
  199. },

相关文章

最新文章

更多