timeScale2.html 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="./lib/jquery.min.js"></script>
  5. <script src="lib/esl.js"></script>
  6. <script src="lib/config.js"></script>
  7. </head>
  8. <body>
  9. <style>
  10. html,
  11. body {
  12. padding: 0;
  13. margin: 0;
  14. }
  15. .demo {
  16. position: relative;
  17. margin-top: 100px;
  18. margin-left: 100px;
  19. }
  20. .pc-chart {
  21. width: 540px;
  22. height: 300px;
  23. }
  24. .mobile-box {
  25. position: absolute;
  26. left: 280px;
  27. top: -40px;
  28. width: 215px;
  29. height: 360px;
  30. z-index: 300;
  31. user-select: none;
  32. }
  33. .mobile-content {
  34. position: absolute;
  35. overflow: hidden;
  36. width: 150px;
  37. height: 272px;
  38. left: 312px;
  39. top: 0;
  40. background: #333;
  41. z-index: 300;
  42. }
  43. .mobile-chart {
  44. position: absolute;
  45. top: -95px;
  46. left: -75px;
  47. width: 300px;
  48. height: 460px;
  49. }
  50. </style>
  51. <div class="demo">
  52. <div class="pc-chart"></div>
  53. </div>
  54. <script type="text/javascript">
  55. require([
  56. 'echarts'
  57. // 'echarts/chart/line',
  58. // 'echarts/component/legend',
  59. // 'echarts/component/grid',
  60. // 'echarts/component/tooltip',
  61. // 'echarts/component/title',
  62. // 'echarts/component/dataZoom',
  63. // 'echarts/scale/Time'
  64. ], function (echarts) {
  65. var data = {"years":[1800,1810,1820,1830,1840,1850,1860,1870,1880,1890,1900,1910,1920,1930,1940,1950,1951,1952,1953,1954,1955,1956,1957,1958,1959,1960,1961,1962,1963,1964,1965,1966,1967,1968,1969,1970,1971,1972,1973,1974,1975,1976,1977,1978,1979,1980,1981,1982,1983,1984,1985,1986,1987,1988,1989,1990,1991,1992,1993,1994,1995,1996,1997,1998,1999,2000,2001,2002,2003,2004,2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015],"lifeExpectancy":[29.5734572,29.5734572,29.5734572,29.5734572,29.5734572,29.5734572,29.5734572,31.12082604,30.20106663,29.93047652,30.74960789,31.40217766,20.5,36.428,41.056,57.084,57.5768,57.9696,58.7624,60.7552,63.148,64.6408,63.7336,66.6264,67.3692,68.382,68.6248,68.2776,68.7404,69.5332,69.116,69.1788,68.9616,68.9144,68.3872,68.5,68.6,68.7,68.7,68.6,68.2,68,67.8,67.7,67.4,67.3,67.5,67.9,67.7,67.4,68.2,69.8,70.1,70,69.8,69.6,69.4,68,65.2,63.6,64.2,65.9,67.4,67.6,66.2,65.4,65.1,64.9,64.8,65,64.8,66.1,67.2,67.6,68.3,68.7,69.4,70.4,71.3,72.21,73.13],"income":[1430,1447,1464,1562,1666,1778,1896,2023,2158,2233,3087,3487,1489,3779,5632,7514,7424,7775,7981,8234,8787,9465,9496,10037,9755,10496,10908,11027,10620,11836,12363,12823,13256,13902,13972,14915,15170,15113,16236,16594,16530,17192,17487,17818,17632,17557,17619,17951,18417,18527,18576,19221,19355,19660,19906,19349,18332,15661,14320,12535,12013,11597,11779,11173,11925,13173,13902,14629,15768,16967,18118,19660,21374,22506,20739,21664,22570,23299,23561,23293,23038],"population":[31088398,31088398,31861526,34134430,37420913,41023821,44966686,49288504,53996807,59151534,64836675,71044207,77871987,85369549,93588981,102798657,104306354,105969442,107729541,109537868,111355224,113152347,114909562,116615781,118266807,119860289,121390327,122842753,124193114,125412397,126483874,127396324,128165823,128837792,129475269,130126383,130808492,131517584,132254362,133012558,133788113,134583945,135406786,136259517,137144808,138063062,139006739,139969243,140951400,141955200,142975753,144016095,145056221,146040116,146895053,147568552,148040354,148322473,148435811,148416292,148293265,148078355,147772805,147385440,146924174,146400951,145818121,145195521,144583147,144043914,143622566,143338407,143180249,143123163,143126660,143158099,143211476,143287536,143367341,143429435,143456918]};
  66. echarts.util.each(data.years, function (year, index) {
  67. year = +new Date(year, 0, 1);
  68. data.population[index] = [year, data.population[index]];
  69. data.lifeExpectancy[index] = [year, data.lifeExpectancy[index]];
  70. data.income[index] = [year, data.income[index]];
  71. });
  72. var series1Color = '#c23531';
  73. var series2Color = 'rgba(4,127,154,1)';
  74. var series3Color = '#2f4554';
  75. var series3AreaColor = {
  76. x: 0,
  77. x2: 0,
  78. y: 0,
  79. y2: 1,
  80. colorStops: [
  81. {offset: 0, color: series3Color},
  82. {offset: 1, color: 'rgba(0,0,0,0)'}
  83. ]
  84. };
  85. var series2AreaColor = {
  86. x: 0,
  87. x2: 0,
  88. y: 0,
  89. y2: 1,
  90. colorStops: [
  91. {offset: 0, color: 'rgba(4,127,154,0.8)'},
  92. {offset: 1, color: 'rgba(0,0,0,0)'}
  93. ]
  94. };
  95. var y3Formatter = function (val) {
  96. return (val / 1000).toFixed(0) + ' k';
  97. };
  98. var y3AxisPointerFormatter = function (params) {
  99. return (params.value / 1000).toFixed(0) + ' k';
  100. };
  101. var option = {
  102. backgroundColor: '#3aadd1',
  103. // textStyle: {
  104. // fontFamily: 'Tahoma'
  105. // },
  106. tooltip: {
  107. trigger: 'axis',
  108. axisPointer: {
  109. type: 'cross'
  110. },
  111. padding: 5,
  112. backgroundColor: '#eee',
  113. borderColor: '#999',
  114. borderWidth: 1,
  115. textStyle: {
  116. color: '#222'
  117. },
  118. extraCssText: 'z-index: 200'
  119. },
  120. axisPointer: {
  121. link: [{xAxisIndex: 'all'}],
  122. label: {
  123. textStyle: {
  124. color: '#222'
  125. }
  126. },
  127. z: 500
  128. },
  129. xAxis: [{
  130. type: 'time',
  131. splitLine: {
  132. show: false
  133. },
  134. axisTick: {
  135. show: false
  136. },
  137. axisLine: {
  138. show: false,
  139. lineStyle: {
  140. color: '#ddd'
  141. }
  142. },
  143. axisLabel: {
  144. show: false,
  145. textStyle: {
  146. color: '#ddd'
  147. }
  148. },
  149. axisPointer: {
  150. label: {
  151. show: false
  152. }
  153. }
  154. }, {
  155. type: 'time',
  156. gridIndex: 1,
  157. splitLine: {
  158. show: false
  159. },
  160. axisTick: {
  161. show: false,
  162. lineStyle: {
  163. color: '#ddd'
  164. }
  165. },
  166. axisLine: {
  167. show: false,
  168. lineStyle: {
  169. color: '#ddd'
  170. }
  171. },
  172. axisLabel: {
  173. textStyle: {
  174. color: '#ddd'
  175. }
  176. }
  177. }],
  178. yAxis: [{
  179. splitNumber: 3,
  180. nameTextStyle: {
  181. color: '#ccc',
  182. fontSize: 18
  183. },
  184. axisLine: {
  185. lineStyle: {
  186. color: '#ddd'
  187. }
  188. },
  189. axisTick: {
  190. inside: true,
  191. lineStyle: {
  192. color: '#ddd'
  193. }
  194. },
  195. splitLine: {
  196. show: false
  197. },
  198. axisLabel: {
  199. inside: true,
  200. textStyle: {
  201. color: '#ddd'
  202. }
  203. },
  204. axisPointer: {
  205. label: {
  206. textStyle: {
  207. color: series1Color
  208. }
  209. }
  210. },
  211. z: 200
  212. }, {
  213. position: 'right',
  214. splitNumber: 3,
  215. nameTextStyle: {
  216. color: '#ccc',
  217. fontSize: 18
  218. },
  219. axisLine: {
  220. lineStyle: {
  221. color: '#ddd'
  222. }
  223. },
  224. axisTick: {
  225. inside: true,
  226. lineStyle: {
  227. color: '#ddd'
  228. }
  229. },
  230. splitLine: {
  231. show: false
  232. },
  233. axisLabel: {
  234. inside: true,
  235. formatter: function (value) {
  236. return (value / 1000000).toFixed(0) + ' M';
  237. },
  238. textStyle: {
  239. color: '#ddd'
  240. }
  241. },
  242. axisPointer: {
  243. label: {
  244. formatter: function (param) {
  245. return (param.value / 1000000).toFixed(0) + ' M';
  246. },
  247. textStyle: {
  248. color: series2Color
  249. }
  250. }
  251. },
  252. z: 200
  253. }, {
  254. gridIndex: 1,
  255. splitNumber: 1,
  256. nameTextStyle: {
  257. color: '#ccc',
  258. fontSize: 18
  259. },
  260. axisLine: {
  261. lineStyle: {
  262. color: '#ddd'
  263. }
  264. },
  265. axisTick: {
  266. inside: true,
  267. lineStyle: {
  268. color: '#ddd'
  269. }
  270. },
  271. splitLine: {
  272. show: false
  273. },
  274. axisLabel: {
  275. inside: true,
  276. formatter: y3Formatter,
  277. textStyle: {
  278. color: '#ddd'
  279. }
  280. },
  281. axisPointer: {
  282. label: {
  283. formatter: y3AxisPointerFormatter
  284. }
  285. },
  286. z: 40
  287. }],
  288. grid: [{
  289. left: 20,
  290. right: 20,
  291. top: 30,
  292. height: 130
  293. }, {
  294. left: 20,
  295. right: 20,
  296. top: 175,
  297. height: 60
  298. }],
  299. dataZoom: [{
  300. bottom: 10,
  301. height: 20,
  302. left: 18,
  303. handleIcon: 'M10.7,11.9H9.3c-4.9,0.3-8.8,4.4-8.8,9.4c0,5,3.9,9.1,8.8,9.4h1.3c4.9-0.3,8.8-4.4,8.8-9.4C19.5,16.3,15.6,12.2,10.7,11.9z M13.3,24.4H6.7v-1.2h6.6z M13.3,22H6.7v-1.2h6.6z M13.3,19.6H6.7v-1.2h6.6z', // jshint ignore:line
  304. handleSize: '80%',
  305. handleStyle: {
  306. color: '#ddd'
  307. },
  308. labelFormatter: '',
  309. borderColor: 'rgba(0,0,0,0.2)',
  310. xAxisIndex: [0, 1],
  311. // startValue: +new Date(1860, 0, 1),
  312. // endValue: +new Date(1969, 0, 1),
  313. // minValueSpan: new Date(1969, 0, 1) - new Date(1965, 0, 1)
  314. }, {
  315. type: 'inside',
  316. xAxisIndex: [0, 1],
  317. // startValue: +new Date(1860, 0, 1),
  318. // endValue: +new Date(1969, 0, 1)
  319. }],
  320. series: [
  321. {
  322. type: 'line',
  323. name: 'seriesA',
  324. id: 'gridScatter',
  325. showSymbol: false,
  326. symbolSize: 10,
  327. hoverAnimation: false,
  328. itemStyle: {
  329. normal: {
  330. color: series1Color
  331. }
  332. },
  333. data: data.lifeExpectancy
  334. },
  335. {
  336. type: 'line',
  337. name: 'seriesB',
  338. yAxisIndex: 1,
  339. showSymbol: false,
  340. itemStyle: {
  341. normal: {
  342. color: series2Color
  343. }
  344. },
  345. areaStyle: {
  346. normal: {
  347. color: series2AreaColor
  348. }
  349. },
  350. data: data.population
  351. },
  352. {
  353. type: 'line',
  354. name: 'seriesC',
  355. xAxisIndex: 1,
  356. yAxisIndex: 2,
  357. showSymbol: false,
  358. symbolSize: 10,
  359. hoverAnimation: false,
  360. areaStyle: {
  361. normal: {
  362. color: series3AreaColor
  363. }
  364. },
  365. itemStyle: {
  366. normal: {
  367. color: series3Color
  368. }
  369. },
  370. data: data.income
  371. }
  372. ]
  373. };
  374. var myChart = echarts.init($('.pc-chart')[0]);
  375. myChart.setOption(option);
  376. });
  377. </script>
  378. </body>
  379. </html>