map-grid.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. <!DOCTYPE>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="lib/esl.js"></script>
  6. <script src="lib/jquery.min.js"></script>
  7. <script src="lib/config.js"></script>
  8. <meta name="viewport" content="width=device-width, initial-scale=1" />
  9. <link rel="stylesheet" href="lib/reset.css">
  10. </head>
  11. <body>
  12. <style>
  13. </style>
  14. <div id="main"></div>
  15. <script>
  16. var echarts;
  17. var chart;
  18. var myChart;
  19. require([
  20. 'jquery',
  21. 'echarts'
  22. // 'echarts/chart/scatter',
  23. // 'echarts/chart/parallel',
  24. // 'echarts/component/geo',
  25. // 'echarts/component/title',
  26. // 'echarts/component/legend',
  27. // 'echarts/component/brush',
  28. // 'echarts/component/tooltip',
  29. // 'echarts/component/toolbox',
  30. // 'echarts/component/visualMap',
  31. // 'echarts/component/timeline'
  32. ], function ($, ec) {
  33. echarts = ec;
  34. require(['map/js/world'], function () {
  35. chart = myChart = echarts.init(document.getElementById('main'), null, {
  36. });
  37. // -------------------------------------------------------------------
  38. // -------------------------------------------------------------------
  39. // -------------------------------------------------------------------
  40. myChart.showLoading();
  41. $.getJSON('data/life-expectancy.json', function (data) {
  42. myChart.hideLoading();
  43. var itemStyle = {
  44. normal: {
  45. opacity: 0.8,
  46. shadowBlur: 10,
  47. shadowOffsetX: 0,
  48. shadowOffsetY: 0,
  49. shadowColor: 'rgba(0, 0, 0, 0.5)'
  50. }
  51. };
  52. var sizeFunction = function (x) {
  53. var y = Math.sqrt(x / 5e8) + 0.1;
  54. return y * 40;
  55. };
  56. // Schema:
  57. var schema = [
  58. {name: 'Income', index: 0, text: '人均收入', unit: '美元'},
  59. {name: 'LifeExpectancy', index: 1, text: '人均寿命', unit: '岁'},
  60. {name: 'Population', index: 2, text: '总人口', unit: ''},
  61. {name: 'Country', index: 3, text: '国家', unit: ''}
  62. ];
  63. option = {
  64. baseOption: {
  65. timeline: {
  66. axisType: 'category',
  67. orient: 'vertical',
  68. autoPlay: true,
  69. inverse: true,
  70. playInterval: 1000,
  71. left: null,
  72. right: 10,
  73. top: 20,
  74. bottom: 20,
  75. width: 55,
  76. height: null,
  77. label: {
  78. normal: {
  79. textStyle: {
  80. color: '#ddd'
  81. }
  82. },
  83. emphasis: {
  84. textStyle: {
  85. color: '#fff'
  86. }
  87. }
  88. },
  89. symbol: 'none',
  90. lineStyle: {
  91. color: '#555'
  92. },
  93. checkpointStyle: {
  94. color: '#bbb',
  95. borderColor: '#777',
  96. borderWidth: 2
  97. },
  98. controlStyle: {
  99. showNextBtn: false,
  100. showPrevBtn: false,
  101. normal: {
  102. color: '#666',
  103. borderColor: '#666'
  104. },
  105. emphasis: {
  106. color: '#aaa',
  107. borderColor: '#aaa'
  108. }
  109. },
  110. data: []
  111. },
  112. backgroundColor: '#333',
  113. title: {
  114. 'text': data.timeline[0],
  115. textAlign: 'center',
  116. right: '3%',
  117. top: '73%',
  118. textStyle: {
  119. fontSize: 100,
  120. color: 'rgba(255, 255, 255, 0.9)'
  121. }
  122. },
  123. tooltip: {
  124. padding: 5,
  125. backgroundColor: '#222',
  126. borderColor: '#777',
  127. borderWidth: 1
  128. },
  129. xAxis: {
  130. type: 'log',
  131. name: '人均收入',
  132. max: 100000,
  133. min: 300,
  134. nameGap: 25,
  135. nameLocation: 'middle',
  136. nameTextStyle: {
  137. fontSize: 18
  138. },
  139. splitLine: {
  140. show: false
  141. },
  142. axisTick: {
  143. lineStyle: {
  144. color: '#ddd'
  145. }
  146. },
  147. axisLine: {
  148. lineStyle: {
  149. color: '#ddd'
  150. }
  151. },
  152. axisLabel: {
  153. formatter: '{value} $',
  154. textStyle: {
  155. color: '#ddd'
  156. }
  157. }
  158. },
  159. yAxis: {
  160. type: 'value',
  161. name: '平均寿命',
  162. nameGap: 25,
  163. max: 100,
  164. nameTextStyle: {
  165. color: '#ccc',
  166. fontSize: 18
  167. },
  168. axisLine: {
  169. lineStyle: {
  170. color: '#ddd'
  171. }
  172. },
  173. axisTick: {
  174. lineStyle: {
  175. color: '#ddd'
  176. }
  177. },
  178. splitLine: {
  179. show: false
  180. },
  181. axisLabel: {
  182. formatter: '{value} 岁',
  183. textStyle: {
  184. color: '#ddd'
  185. }
  186. }
  187. },
  188. grid: {
  189. top: '40%',
  190. left: 200,
  191. right: 110
  192. },
  193. geo: {
  194. top: 20,
  195. left: 170,
  196. right: 120,
  197. height: '38%',
  198. name: 'World Population (2010)',
  199. type: 'map',
  200. map: 'world',
  201. roam: false,
  202. label: {
  203. emphasis: {
  204. show: false
  205. }
  206. },
  207. itemStyle: {
  208. normal: {
  209. borderColor: '#aaa',
  210. areaColor: '#555'
  211. },
  212. emphasis: {
  213. areaColor: '#555'
  214. }
  215. }
  216. },
  217. toolbox: {
  218. // orient: 'vertical',
  219. top: 25,
  220. left: 10,
  221. itemSize: 20,
  222. // itemGap: 17,
  223. iconStyle: {
  224. normal: {
  225. borderColor: '#eee'
  226. },
  227. emphasis: {
  228. borderColor: '#fffb60'
  229. }
  230. }
  231. },
  232. brush: {
  233. toolbox: ['polygon', 'keep', 'clear'],
  234. brushLink: 'all',
  235. xAxisIndex: 0,
  236. geoIndex: 0,
  237. outOfBrush: {
  238. opacity: .1,
  239. color: '#aaa'
  240. }
  241. },
  242. visualMap: [
  243. {
  244. type: 'piecewise',
  245. dimension: 3,
  246. categories: data.countries.map(function (item) {
  247. return item[2];
  248. }),
  249. left: 10,
  250. bottom: 35,
  251. calculable: true,
  252. precision: 0.1,
  253. textGap: 10,
  254. itemGap: 12,
  255. textStyle: {
  256. color: '#ccc'
  257. },
  258. inRange: {
  259. color: ['#bcd3bb', '#e88f70', '#edc1a5', '#9dc5c8', '#e1e8c8', '#7b7c68', '#e5b5b5', '#f0b489', '#928ea8', '#bda29a', '#376956', '#c3bed4', '#495a80', '#9966cc', '#bdb76a', '#eee8ab', '#a35015', '#04dd98', '#d9b3e6']
  260. },
  261. outOfRange: {
  262. color: '#555'
  263. }
  264. }
  265. ],
  266. series: [
  267. {
  268. type: 'scatter',
  269. id: 'gridScatter',
  270. itemStyle: itemStyle,
  271. data: data.series[0],
  272. symbolSize: function(val) {
  273. return sizeFunction(val[2]);
  274. },
  275. tooltip: {
  276. formatter: function (obj) {
  277. var value = obj.value;
  278. return schema[3].text + ':' + value[3] + '<br>'
  279. + schema[1].text + ':' + value[1] + schema[1].unit + '<br>'
  280. + schema[0].text + ':' + value[0] + schema[0].unit + '<br>'
  281. + schema[2].text + ':' + value[2] + '<br>';
  282. }
  283. }
  284. },
  285. {
  286. type: 'scatter',
  287. id: 'geoScatter',
  288. coordinateSystem: 'geo',
  289. itemStyle: {
  290. normal: {
  291. opacity: 1,
  292. shadowBlur: 5,
  293. shadowColor: 'rgba(0, 0, 0, 0.5)'
  294. },
  295. },
  296. data: data.countries.map(function (item) {
  297. return [item[0], item[1], 0, item[2]];
  298. }),
  299. symbolSize: 15,
  300. tooltip: {
  301. formatter: function (obj) {
  302. var value = obj.value;
  303. return schema[3].text + ':' + value[3];
  304. }
  305. }
  306. }
  307. ],
  308. animationDurationUpdate: 1000,
  309. animationEasingUpdate: 'quinticInOut'
  310. },
  311. options: []
  312. };
  313. for (var n = 0; n < data.timeline.length; n++) {
  314. option.baseOption.timeline.data.push(data.timeline[n]);
  315. option.options.push({
  316. title: {
  317. show: true,
  318. 'text': data.timeline[n] + ''
  319. },
  320. series: {
  321. id: 'gridScatter',
  322. name: data.timeline[n],
  323. type: 'scatter',
  324. itemStyle: itemStyle,
  325. data: data.series[n],
  326. symbolSize: function(val) {
  327. return sizeFunction(val[2]);
  328. }
  329. }
  330. });
  331. }
  332. myChart.setOption(option);
  333. });
  334. // -------------------------------------------------------------------
  335. // -------------------------------------------------------------------
  336. // -------------------------------------------------------------------
  337. })
  338. });
  339. </script>
  340. </body>
  341. </html>