lemon_echarts_map_statistics

功能描述

echarts中国地图数据显示,是在echarts基础上扩展的地图热点数据显示功能

依赖的模块

  1. ECharts

快速使用

  1. <div id="map_1" style="height: 600px;width: 1000px;"></div>
  2. <script type="text/javascript" src="./script/echarts.min.js"></script>
  3. <script type="text/javascript" src="./script/china.js"></script>
  4. <script type="text/javascript">
  5. var data2 = [
  6. {name: '商丘', value: 9},
  7. {name: '鄂尔多斯', value: 12},
  8. {name: '招远', value: 12},
  9. {name: '舟山', value: 12},
  10. {name: '日照', value: 21},
  11. {name: '胶南', value: 22},
  12. {name: '大庆', value: 279}
  13. ];
  14. var convertData = function (data) {
  15. var res = [];
  16. for (var i = 0; i < data.length; i++) {
  17. var geoCoord = geoCoordMap[data[i].name];
  18. if (geoCoord) {
  19. res.push({
  20. name: data[i].name,
  21. value: geoCoord.concat(data[i].value)
  22. });
  23. }
  24. }
  25. return res;
  26. };
  27. //地图容器
  28. var map_1 = echarts.init(document.getElementById('map_1'));
  29. //地图容器
  30. //34个省、市、自治区的名字拼音映射数组
  31. //网络零售当期分布
  32. var map_1_option = {
  33. tooltip : {
  34. trigger: 'item'
  35. },
  36. geo: {
  37. map: 'china',
  38. label: {
  39. emphasis: {
  40. show: false
  41. }
  42. },
  43. roam: false,
  44. itemStyle: {
  45. normal: {
  46. areaColor: '#d1d1d1',
  47. borderColor: '#111',
  48. },
  49. emphasis: {
  50. areaColor: '#d1d1d1'
  51. }
  52. }
  53. },
  54. series : [
  55. {
  56. name: 'Top 5',
  57. type: 'effectScatter',
  58. coordinateSystem: 'geo',
  59. symbolSize: function (val) {
  60. return val[2] / 10;
  61. },
  62. showEffectOn: 'render',
  63. rippleEffect: {
  64. brushType: 'stroke'
  65. },
  66. hoverAnimation: true,
  67. itemStyle: {
  68. normal: {
  69. color: '#f75749',
  70. shadowBlur: 10,
  71. shadowColor: '#333'
  72. }
  73. },
  74. zlevel: 1
  75. }
  76. ]
  77. };
  78. var data = [
  79. {
  80. "name":"北京市", "log":"116.46", "lat":"39.92",
  81. "children":[
  82. {"name":"北京", "log":"116.46", "lat":"39.92"},
  83. {"name":"昌平", "log":"116.2", "lat":"40.22"}
  84. ]
  85. },
  86. {
  87. "name":"上海市", "log":"121.48", "lat":"31.22",
  88. "children":[
  89. {"name":"上海", "log":"121.48", "lat":"31.22"},
  90. {"name":"嘉定", "log":"121.24", "lat":"31.4"},
  91. {"name":"宝山", "log":"121.48", "lat":"31.41"},
  92. {"name":"崇明", "log":"121.4", "lat":"31.73"}
  93. ]
  94. },
  95. {
  96. "name":"天津市", "log":"117.2", "lat":"39.13",
  97. "children":[
  98. {"name":"天津", "log":"117.2", "lat":"39.13"},
  99. {"name":"宁河", "log":"117.83", "lat":"39.33"},
  100. {"name":"宝坻", "log":"117.3", "lat":"39.75"},
  101. {"name":"武清", "log":"117.05", "lat":"39.4"}
  102. ]
  103. }
  104. ];
  105. var geoCoordMap = {
  106. };
  107. for (infoIndex = 0; infoIndex < data.length; infoIndex++) {
  108. var info = data[infoIndex];
  109. var city = info.children;
  110. for(var i =0;i<city.length;i++){
  111. var citydetail = new Array();
  112. var name = city[i].name;
  113. geoCoordMap[name]= citydetail;
  114. var lat = parseFloat(city[i].lat);
  115. var log = parseFloat(city[i].log);
  116. citydetail.push(log);
  117. citydetail.push(lat);
  118. }
  119. }
  120. map_1_option.series[0].data = convertData(data2.sort(function (a, b) {
  121. return b.value - a.value;
  122. })),
  123. map_1.setOption(map_1_option);
  124. </script>

特别说明

  1. 1、参数不限制, 例如:var data = [{name:'城市名称',lon:'经度',lat:'纬度'}];
  2. 2、回调可用log查看自定义参数,不限制
  3. 3、使用本模块注意会与同ECharts模块冲突,请开发者谨慎选择,本模块为1.0版本,后续会陆续更新。