timeline-layout.html 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352
  1. <html>
  2. <head>
  3. <meta charset="utf-8">
  4. <script src="esl.js"></script>
  5. <script src="config.js"></script>
  6. <meta name="viewport" content="width=device-width, initial-scale=1" />
  7. </head>
  8. <body>
  9. <style>
  10. html, body, #main {
  11. width: 100%;
  12. height: 100%;
  13. margin: 0;
  14. background: #ccc;
  15. }
  16. .block {
  17. text-align: center;
  18. margin: 20px;
  19. }
  20. .block .ec {
  21. background: #fff;
  22. width: 700px;
  23. height: 400px;
  24. margin: 5px auto;
  25. }
  26. </style>
  27. <div id="main"></div>
  28. <script src="data/timelineGDP.js"></script>
  29. <script>
  30. require([
  31. 'echarts',
  32. 'zrender/core/util',
  33. 'echarts/chart/bar',
  34. 'echarts/component/legend',
  35. 'echarts/component/grid',
  36. 'echarts/component/tooltip',
  37. 'echarts/component/timeline'
  38. ], function (echarts, zrUtil) {
  39. makeChart({});
  40. makeChart({timeline: {inverse: true}});
  41. makeChart({timeline: {inverse: true, controlStyle: {position: 'right'}}});
  42. makeChart({timeline: {orient: 'vertical', x: 0, y: 10, width: 55, height: '80%'}});
  43. makeChart({timeline: {orient: 'vertical', inverse: true, rewind: true, x: 0, y: 10, width: 55, height: '80%'}});
  44. makeChart({timeline: {orient: 'vertical', inverse: true, x: null, x2: 0, y: 10, width: 55, height: '80%'}});
  45. makeChart({timeline: {orient: 'vertical', inverse: true, x: null, x2: 0, y: 10, width: 55, height: '80%', controlStyle: {position: 'top'}}});
  46. makeChart({timeline: {label: {position: 'top'}}});
  47. makeChart({timeline: {orient: 'vertical', inverse: true, x: null, x2: 0, y: 10, width: 55, height: '80%', label: {position: 'right'}}});
  48. makeChart({timeline: {orient: 'vertical', inverse: true, x: null, x2: 0, y: 10, width: 55, height: '80%', label: {position: -640, emphasis: {textStyle: {fontSize: 20}}}}});
  49. makeChart({timeline: {controlStyle: {show: false}}});
  50. makeChart({timeline: {controlStyle: {showPlayBtn: false}}});
  51. makeChart({timeline: {controlStyle: {showPrevBtn: false}}});
  52. makeChart({timeline: {controlStyle: {showNextBtn: false}}});
  53. makeChart({timeline: {}});
  54. makeChart({
  55. timeline: {lineStyle: {show: false},
  56. symbol: 'circle',
  57. itemStyle: {normal: {color: 'rgba(194,53,49, 0.5)'}},
  58. controlStyle: {showPrevBtn: false, showNextBtn: false, normal: {color: 'rgba(194,53,49, 0.5)', borderColor: 'rgba(194,53,49, 0.5)'}},
  59. orient: 'vertical', inverse: true, x: 0, y: 40, width: 55, height: '80%'
  60. }});
  61. makeChart({
  62. timeline: {
  63. height: 55,
  64. data: [
  65. '2002-01-01','2003-01-01','2004-01-01','2005-01-01',
  66. {
  67. value: '2006-01-01',
  68. symbol: 'pin',
  69. symbolSize: 30
  70. },
  71. '2007-01-01','2008-01-01','2009-01-01','2010-01-01',
  72. {
  73. value: '2011-01-01',
  74. symbol: 'pin',
  75. symbolSize: 30
  76. }
  77. ]
  78. }
  79. });
  80. makeChart({
  81. timeline: {
  82. symbol: 'none'
  83. }
  84. });
  85. function makeChart(opt) {
  86. opt = opt || {};
  87. var containerEl = document.getElementById('main');
  88. var el = document.createElement('div');
  89. el.className = 'block';
  90. el.innerHTML = '<div class="ec"></div><label>'
  91. + encodeHTML(JSON.stringify(opt)) + '</label>';
  92. containerEl.appendChild(el);
  93. var chart = echarts.init(el.firstChild, null, {renderer: 'canvas'});
  94. chart.setOption(getOption(opt));
  95. }
  96. function encodeHTML(source) {
  97. return source == null
  98. ? ''
  99. : String(source)
  100. .replace(/&/g, '&amp;')
  101. .replace(/</g, '&lt;')
  102. .replace(/>/g, '&gt;')
  103. .replace(/"/g, '&quot;')
  104. .replace(/'/g, '&#39;');
  105. };
  106. function getOption(opt) {
  107. return zrUtil.merge({
  108. timeline:{
  109. // y: 0,
  110. axisType: 'category',
  111. // realtime: false,
  112. // loop: false,
  113. autoPlay : false,
  114. // currentIndex: 2,
  115. playInterval : 1000,
  116. // controlStyle: {
  117. // position: 'left'
  118. // },
  119. data: [
  120. '2002-01-01','2003-01-01','2004-01-01','2005-01-01','2006-01-01',
  121. '2007-01-01','2008-01-01','2009-01-01','2010-01-01','2011-01-01'
  122. ],
  123. label: {
  124. formatter : function(s) {
  125. return (new Date(s)).getFullYear();
  126. }
  127. },
  128. controlStyle: {
  129. // itemGap: 0,
  130. normal: {
  131. borderWidth: 1
  132. }
  133. },
  134. itemStyle: {
  135. // normal: {symbolSize: 1}
  136. }
  137. },
  138. baseOption: {
  139. backgroundColor: '#fff',
  140. title: {
  141. 'subtext':'数据来自国家统计局'
  142. },
  143. tooltip: {'trigger':'axis'},
  144. calculable : true,
  145. grid : {
  146. x: 120, x2: 120, y: 80, y2: 100
  147. },
  148. xAxis : [
  149. {
  150. 'type':'category',
  151. 'axisLabel':{'interval':0},
  152. 'data':[
  153. '北京','\n天津','河北','\n山西','内蒙古','\n辽宁','吉林','\n黑龙江',
  154. '上海','\n江苏','浙江','\n安徽','福建','\n江西','山东','\n河南',
  155. '湖北','\n湖南','广东','\n广西','海南','\n重庆','四川','\n贵州',
  156. '云南','\n西藏','陕西','\n甘肃','青海','\n宁夏','新疆'
  157. ],
  158. splitLine: {show: false}
  159. }
  160. ],
  161. yAxis : [
  162. {
  163. 'type':'value',
  164. 'name':'GDP(亿元)',
  165. 'max':53500
  166. },
  167. {
  168. 'type':'value',
  169. 'name':'其他(亿元)',
  170. splitLine: {show: false}
  171. }
  172. ],
  173. series: [
  174. {
  175. name: 'GDP',
  176. type: 'bar',
  177. markLine: {
  178. symbol : ['arrow','none'],
  179. symbolSize : [4, 2],
  180. itemStyle : {
  181. normal: {
  182. lineStyle: {color:'orange'},
  183. barBorderColor:'orange',
  184. label:{
  185. position:'left',
  186. formatter:function(params){
  187. return Math.round(params.value);
  188. },
  189. textStyle:{color:'orange'}
  190. }
  191. }
  192. },
  193. 'data':[{'type':'average','name':'平均值'}]
  194. }
  195. }
  196. // {type: 'bar'},
  197. // {type: 'bar'},
  198. // {type: 'bar'},
  199. // {type: 'bar'},
  200. // {type: 'bar'}
  201. ]
  202. },
  203. options: [
  204. {
  205. title : {text: '2002全国宏观经济指标'},
  206. series : [
  207. {
  208. 'name':'GDP',
  209. 'data': dataMap.dataGDP['2002']
  210. },
  211. {
  212. 'name':'金融','yAxisIndex':1,'type':'bar',
  213. 'data': dataMap.dataFinancial['2002']
  214. },
  215. {
  216. 'name':'房地产','yAxisIndex':1,'type':'bar',
  217. 'data': dataMap.dataEstate['2002']
  218. },
  219. {
  220. 'name':'第一产业','yAxisIndex':1,'type':'bar',
  221. 'data': dataMap.dataPI['2002']
  222. },
  223. {
  224. 'name':'第二产业','yAxisIndex':1,'type':'bar',
  225. 'data': dataMap.dataSI['2002']
  226. },
  227. {
  228. 'name':'第三产业','yAxisIndex':1,'type':'bar',
  229. 'data': dataMap.dataTI['2002']
  230. }
  231. ]
  232. },
  233. {
  234. title : {'text':'2003全国宏观经济指标'},
  235. series : [
  236. {'data': dataMap.dataGDP['2003']},
  237. {'data': dataMap.dataFinancial['2003']},
  238. {'data': dataMap.dataEstate['2003']},
  239. {'data': dataMap.dataPI['2003']},
  240. {'data': dataMap.dataSI['2003']},
  241. {'data': dataMap.dataTI['2003']}
  242. ]
  243. },
  244. {
  245. title : {'text':'2004全国宏观经济指标'},
  246. series : [
  247. {'data': dataMap.dataGDP['2004']},
  248. {'data': dataMap.dataFinancial['2004']},
  249. {'data': dataMap.dataEstate['2004']},
  250. {'data': dataMap.dataPI['2004']},
  251. {'data': dataMap.dataSI['2004']},
  252. {'data': dataMap.dataTI['2004']}
  253. ]
  254. },
  255. {
  256. title : {'text':'2005全国宏观经济指标'},
  257. series : [
  258. {'data': dataMap.dataGDP['2005']},
  259. {'data': dataMap.dataFinancial['2005']},
  260. {'data': dataMap.dataEstate['2005']},
  261. {'data': dataMap.dataPI['2005']},
  262. {'data': dataMap.dataSI['2005']},
  263. {'data': dataMap.dataTI['2005']}
  264. ]
  265. },
  266. {
  267. title : {'text':'2006全国宏观经济指标'},
  268. series : [
  269. {'data': dataMap.dataGDP['2006']},
  270. {'data': dataMap.dataFinancial['2006']},
  271. {'data': dataMap.dataEstate['2006']},
  272. {'data': dataMap.dataPI['2006']},
  273. {'data': dataMap.dataSI['2006']},
  274. {'data': dataMap.dataTI['2006']}
  275. ]
  276. },
  277. {
  278. title : {'text':'2007全国宏观经济指标'},
  279. series : [
  280. {'data': dataMap.dataGDP['2007']},
  281. {'data': dataMap.dataFinancial['2007']},
  282. {'data': dataMap.dataEstate['2007']},
  283. {'data': dataMap.dataPI['2007']},
  284. {'data': dataMap.dataSI['2007']},
  285. {'data': dataMap.dataTI['2007']}
  286. ]
  287. },
  288. {
  289. title : {'text':'2008全国宏观经济指标'},
  290. series : [
  291. {'data': dataMap.dataGDP['2008']},
  292. {'data': dataMap.dataFinancial['2008']},
  293. {'data': dataMap.dataEstate['2008']},
  294. {'data': dataMap.dataPI['2008']},
  295. {'data': dataMap.dataSI['2008']},
  296. {'data': dataMap.dataTI['2008']}
  297. ]
  298. },
  299. {
  300. title : {'text':'2009全国宏观经济指标'},
  301. series : [
  302. {'data': dataMap.dataGDP['2009']},
  303. {'data': dataMap.dataFinancial['2009']},
  304. {'data': dataMap.dataEstate['2009']},
  305. {'data': dataMap.dataPI['2009']},
  306. {'data': dataMap.dataSI['2009']},
  307. {'data': dataMap.dataTI['2009']}
  308. ]
  309. },
  310. {
  311. title : {'text':'2010全国宏观经济指标'},
  312. series : [
  313. {'data': dataMap.dataGDP['2010']},
  314. {'data': dataMap.dataFinancial['2010']},
  315. {'data': dataMap.dataEstate['2010']},
  316. {'data': dataMap.dataPI['2010']},
  317. {'data': dataMap.dataSI['2010']},
  318. {'data': dataMap.dataTI['2010']}
  319. ]
  320. },
  321. {
  322. title : {'text':'2011全国宏观经济指标'},
  323. series : [
  324. {'data': dataMap.dataGDP['2011']},
  325. {'data': dataMap.dataFinancial['2011']},
  326. {'data': dataMap.dataEstate['2011']},
  327. {'data': dataMap.dataPI['2011']},
  328. {'data': dataMap.dataSI['2011']},
  329. {'data': dataMap.dataTI['2011']}
  330. ]
  331. }
  332. ]
  333. }, opt, true);
  334. }
  335. });
  336. </script>
  337. </body>
  338. </html>