echartsEarthquake.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. <!--********************************************************************
  2. * Copyright© 2000 - 2021 SuperMap Software Co.Ltd. All rights reserved.
  3. *********************************************************************-->
  4. <!DOCTYPE html>
  5. <html>
  6. <head>
  7. <meta charset="UTF-8">
  8. <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width">
  9. <title data-i18n="resources.title_echartsEarthquake"></title>
  10. <!-- 此范例基于 openlayers@4.6.5 & ol3-echarts@1.3.6 -->
  11. <script type="text/javascript" include="ol@4.6.5,echarts,ol3-echarts@1.3.6" src="../../dist/ol/include-ol.js"></script>
  12. <style>
  13. body {
  14. margin: 0;
  15. overflow: hidden;
  16. background: #fff;
  17. width: 100%;
  18. height: 100%
  19. }
  20. #map {
  21. position: absolute;
  22. width: 100%;
  23. height: 100%;
  24. }
  25. </style>
  26. </head>
  27. <body>
  28. <div id="map"></div>
  29. <script type="text/javascript" include="jquery,papaparse" src="../js/include-web.js"></script>
  30. <script>
  31. // 加载地图
  32. var host = window.isLocal ? window.server : "https://iserver.supermap.io";
  33. var map, option, url = host + "/iserver/services/map-china400/rest/maps/ChinaDark";
  34. var map = new ol.Map({
  35. target: 'map',
  36. controls: ol.control.defaults({ attributionOptions: { collapsed: false } })
  37. .extend([new ol.supermap.control.Logo()]),
  38. view: new ol.View({
  39. center: [96, 36],
  40. zoom: 5,
  41. minZoom: 5,
  42. projection: 'EPSG:4326',
  43. multiWorld: true
  44. }),
  45. layers: [new ol.layer.Tile({
  46. source: new ol.source.TileSuperMapRest({
  47. url: url,
  48. prjCoordSys: { "epsgCode": 4326 }
  49. }),
  50. projection: 'EPSG:4326'
  51. })]
  52. });
  53. var echartslayer = new ol3Echarts(null, {
  54. hideOnMoving: true,
  55. hideOnZooming: true
  56. });
  57. echartslayer.appendTo(map);
  58. echartslayer.showLoading();
  59. $.get('../data/chinaEarthquake.csv', function (csvstr) {
  60. echartslayer.hideLoading();
  61. var result = Papa.parse(csvstr, { skipEmptyLines: true, header: true }).data;
  62. // 热力图数据
  63. var heatPoints = [];
  64. // 图表数据
  65. var chartData = {};
  66. for (var i = 0; i < result.length; i++) {
  67. var item=result[i];
  68. if (!item.date) continue;
  69. var date = new Date(item.date);
  70. var year = date.getFullYear();
  71. var month = date.getMonth() + 1;
  72. var point = [parseFloat(item.X), parseFloat(item.Y), parseFloat(item.level)];
  73. //每一年的地震数据
  74. if (heatPoints[year]) {
  75. heatPoints[year].push(point);
  76. } else {
  77. heatPoints[year] = [point];
  78. }
  79. //每年每发生的地震次数
  80. if (!chartData[year]) {
  81. chartData[year] = {};
  82. chartData[year][month] = 1;
  83. } else {
  84. if (!chartData[year][month]) {
  85. chartData[year][month] = 1;
  86. } else {
  87. chartData[year][month]++;
  88. }
  89. }
  90. }
  91. //echarts option
  92. var option = {
  93. baseOption: {
  94. animationDurationUpdate: 1000,
  95. animationEasingUpdate: 'quinticInOut',
  96. timeline: {
  97. axisType: 'category',
  98. orient: 'vertical',
  99. autoPlay: true,
  100. inverse: true,
  101. playInterval: 3000,
  102. left: null,
  103. right: 30,
  104. top: 20,
  105. bottom: 40,
  106. width: 55,
  107. height: null,
  108. label: {
  109. normal: { textStyle: { color: '#ddd' } },
  110. emphasis: { textStyle: { color: '#fff' } }
  111. },
  112. symbol: 'none',
  113. lineStyle: { color: '#555' },
  114. checkpointStyle: { color: '#bbb', borderColor: '#777', borderWidth: 2 },
  115. controlStyle: {
  116. showNextBtn: false,
  117. showPrevBtn: false,
  118. normal: { color: '#666', borderColor: '#666' },
  119. emphasis: { color: '#aaa', borderColor: '#aaa' }
  120. },
  121. data: ['2005', '2006', '2007', '2008', '2009', '2010', '2011', '2012', '2013', '2014', '2015', '2016']
  122. },
  123. title: {
  124. text: resources.text_echartsEarthquake_title,
  125. subtext: resources.text_echartsEarthquake_sub_title,
  126. left: 'center',
  127. top: 50,
  128. textStyle: { fontSize: 25, color: 'rgba(255,255,255, 0.9)' }
  129. }
  130. },
  131. options: []
  132. }
  133. //options
  134. for (var j = 2005; j <= 2016; j++) {
  135. var dataAxis = ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'];
  136. var echartsChartData = [
  137. chartData[j][1], chartData[j][2], chartData[j][3], chartData[j][4],
  138. chartData[j][5], chartData[j][6], chartData[j][7], chartData[j][8],
  139. chartData[j][9], chartData[j][10], chartData[j][11], chartData[j][12]
  140. ];
  141. var yMax = 400;
  142. var dataShadow = [];
  143. for (var i = 0; i < echartsChartData.length; i++) {
  144. dataShadow.push(yMax);
  145. }
  146. option.options.push({
  147. visualMap: {
  148. show: false,
  149. top: 'top',
  150. min: 0,
  151. max: 5,
  152. seriesIndex: 0,
  153. calculable: true,
  154. inRange: { color: ['blue', 'blue', 'green', 'yellow', 'red'] }
  155. },
  156. grid: {
  157. left: 50,
  158. bottom: '10%',
  159. width: '30%',
  160. height: '30%',
  161. textStyle: {
  162. color: "#fff"
  163. },
  164. },
  165. tooltip: {
  166. trigger: "item",
  167. textStyle: {
  168. fontSize: 12
  169. },
  170. formatter: "{b0}:{c0}"
  171. },
  172. xAxis: [{
  173. type: "category",
  174. axisLine: {
  175. lineStyle: { color: '#90979c' }
  176. },
  177. splitLine: { show: false },
  178. axisTick: { show: false },
  179. splitArea: { show: false },
  180. xisLabel: { interval: 0, },
  181. data: dataAxis,
  182. }],
  183. yAxis: [{
  184. type: "value",
  185. splitLine: { show: false },
  186. axisLine: {
  187. lineStyle: { color: '#90979c' }
  188. },
  189. axisTick: { show: false },
  190. axisLabel: { interval: 0, },
  191. splitArea: { show: false }
  192. }],
  193. series: [
  194. // heatmap
  195. {
  196. type: 'heatmap',
  197. coordinateSystem: "openlayers",
  198. data: heatPoints[j],
  199. pointSize: 5,
  200. blurSize: 15
  201. },
  202. // For shadow bar
  203. {
  204. type: 'bar',
  205. itemStyle: {
  206. normal: { color: 'rgba(0,0,0,0.05)' }
  207. },
  208. barGap: '-100%',
  209. barCategoryGap: '40%',
  210. data: dataShadow,
  211. animation: false
  212. },
  213. // bar
  214. {
  215. type: 'bar',
  216. itemStyle: {
  217. normal: {
  218. color: new echarts.graphic.LinearGradient(
  219. 0, 0, 0, 1,
  220. [
  221. { offset: 0, color: 'red' },
  222. { offset: 0.5, color: 'yellow' },
  223. { offset: 1, color: 'red' }
  224. ]
  225. ),
  226. barBorderRadius: 15
  227. },
  228. emphasis: {
  229. color: new echarts.graphic.LinearGradient(
  230. 0, 0, 0, 1,
  231. [
  232. { offset: 0, color: 'red' },
  233. { offset: 0.7, color: 'yellow' },
  234. { offset: 1, color: 'red' }
  235. ]
  236. )
  237. },
  238. },
  239. barWidth: 20,
  240. bargap: 5,
  241. data: echartsChartData
  242. },
  243. // line
  244. {
  245. type: "line",
  246. symbolSize: 10,
  247. symbol: 'circle',
  248. itemStyle: {
  249. normal: {
  250. color: "rgba(252,230,48,1)",
  251. barBorderRadius: 0,
  252. label: {
  253. show: true,
  254. position: "top",
  255. formatter: function (p) { return p.value > 0 ? (p.value) : ''; }
  256. }
  257. }
  258. },
  259. data: echartsChartData
  260. },
  261. // pie
  262. {
  263. type: 'pie',
  264. radius: '30%',
  265. center: ['15%', '25%'],
  266. data: [
  267. { value: echartsChartData[0] + echartsChartData[1] + echartsChartData[2], name: resources.text_quarter_1 },
  268. { value: echartsChartData[3] + echartsChartData[4] + echartsChartData[5], name: resources.text_quarter_2 },
  269. { value: echartsChartData[6] + echartsChartData[7] + echartsChartData[8], name: resources.text_quarter_3 },
  270. { value: echartsChartData[9] + echartsChartData[10] + echartsChartData[11], name: resources.text_quarter_4 }
  271. ].sort(function (a, b) {
  272. return a.value - b.value
  273. }),
  274. roseType: 'angle',
  275. label: {
  276. normal: {
  277. textStyle: {
  278. color: 'rgba(255, 255, 255, 0.7)'
  279. }
  280. }
  281. },
  282. labelLine: {
  283. normal: {
  284. lineStyle: {
  285. color: 'rgba(255, 255, 255, 0.7)'
  286. },
  287. smooth: 0.2,
  288. length: 10,
  289. length2: 20
  290. }
  291. },
  292. itemStyle: {
  293. normal: {
  294. color: 'orange',
  295. shadowBlur: 200,
  296. shadowColor: 'rgba(0, 0, 0, 0.5)'
  297. }
  298. },
  299. animationType: 'scale',
  300. animationEasing: 'elasticOut',
  301. animationDelay: function (idx) {
  302. return Math.random() * 200;
  303. }
  304. }
  305. ]
  306. })
  307. }
  308. echartslayer.setChartOptions(option);
  309. });
  310. </script>
  311. </body>
  312. </html>