当前位置:   article > 正文

echarts带时间轴的折线图。_echarts 时间轴折线图

echarts 时间轴折线图

代码:

  1. let echartData = dataxj4['分能源品种碳排放'];
  2. let timeLineData = Array.from(new Set(echartData.map(item => item['年份'])))
  3. let xNameData = Array.from(new Set(echartData.map(item => item['行业'])))
  4. let legendData = ['合计','煤炭','石油','天然气','过程'];
  5. let myChart = echarts.init(document.getElementById('right2'));
  6. //option
  7. let option = {
  8. baseOption: {
  9. timeline: {
  10. data: timeLineData,
  11. axisType: 'category',
  12. autoPlay: true,
  13. playInterval: 5000,
  14. show: true,
  15. left: '10%',
  16. right: '12.5%',
  17. bottom: '0%',
  18. label: {
  19. normal: {
  20. textStyle: {
  21. color: '#ddd',
  22. // rotate: 45
  23. },
  24. interval: 0,
  25. // fontSize: 12,
  26. padding: [0, 0, 0, 0],
  27. // rotate: 45
  28. },
  29. emphasis: {
  30. textStyle: {
  31. color: '#fff'
  32. }
  33. }
  34. },
  35. itemStyle: {
  36. normal: {
  37. color: '#fff',
  38. borderColor: '#2998ff',
  39. borderWidth: 1,
  40. }
  41. },
  42. symbolSize: 10,
  43. lineStyle: {
  44. show: true, //false 不显示轴线
  45. color: '#2998ff',
  46. },
  47. checkpointStyle: {
  48. borderColor: '#777',
  49. borderWidth: 2
  50. },
  51. controlStyle: {
  52. showNextBtn: true,
  53. showPrevBtn: true,
  54. normal: {
  55. color: "#2998ff",
  56. borderColor: "#2998ff"
  57. },
  58. emphasis: {
  59. color: '#aaa',
  60. borderColor: '#aaa'
  61. }
  62. },
  63. },
  64. tooltip: {
  65. trigger: 'item'
  66. },
  67. grid: {
  68. top: 80
  69. }
  70. },
  71. options: [],
  72. }
  73. //数据push
  74. for (let i = 0; i < timeLineData.length; i++) {
  75. let arr1 = [], arr2 = [], arr3 = [], arr4 = [], arr5 = [];
  76. echartData.forEach(item => {
  77. if (item['年份'] == timeLineData[i]) {
  78. arr1.push(item[legendData[0]])
  79. arr2.push(item[legendData[1]])
  80. arr3.push(item[legendData[2]])
  81. arr4.push(item[legendData[3]])
  82. arr5.push(item[legendData[4]])
  83. }
  84. })
  85. option.options.push({
  86. title: {
  87. show: true,
  88. // text: '测试'
  89. },
  90. tooltip: {
  91. trigger: 'axis'
  92. },
  93. legend: {
  94. show: true,
  95. data: legendData
  96. },
  97. calculable: true,
  98. xAxis: [{
  99. type: 'category',
  100. data: xNameData,
  101. axisLabel: {
  102. formatter: '{value} ',
  103. show: true,
  104. textStyle: {
  105. color: "rgba(225, 225, 225,1)",
  106. // fontSize: '12',
  107. },
  108. },
  109. axisTick: {
  110. show: false,
  111. },
  112. axisLine: {
  113. show: true,
  114. lineStyle: {
  115. color: "rgba(255,255,255,.1)",
  116. width: 1,
  117. type: "solid"
  118. },
  119. },
  120. splitLine: {
  121. lineStyle: {
  122. color: "rgba(255,255,255,.1)",
  123. }
  124. }
  125. }],
  126. yAxis: [{
  127. type: 'value',
  128. name: '数量',
  129. // max: 20,
  130. nameTextStyle: {
  131. color: "#fff",
  132. },
  133. axisLabel: {
  134. formatter: '{value} ',
  135. show: true,
  136. textStyle: {
  137. color: "#fff",
  138. // fontSize: '12',
  139. },
  140. },
  141. axisTick: {
  142. show: false,
  143. },
  144. axisLine: {
  145. show: true,
  146. lineStyle: {
  147. color: "rgba(255,255,255,.1)",
  148. width: 1,
  149. type: "solid"
  150. },
  151. },
  152. splitLine: {
  153. lineStyle: {
  154. color: "rgba(255,255,255,.1)",
  155. }
  156. }
  157. }],
  158. series: [
  159. {
  160. name: legendData[0],
  161. type: 'line',
  162. symbolSize: 10,
  163. symbol: 'circle',
  164. itemStyle: {
  165. normal: {
  166. color: '#4E66B2',
  167. barBorderRadius: 0,
  168. label: {
  169. show: false,
  170. }
  171. }
  172. },
  173. // 添加标点
  174. // markPoint: {
  175. // label: {
  176. // normal: {
  177. // show: true,
  178. // align: 'center',
  179. // color: 'WHITE',
  180. // fontWeight: 100,
  181. // formatter: '{b}{c}'
  182. // }
  183. // },
  184. // itemStyle: {
  185. // normal: {
  186. // color: {
  187. // type: 'radial',
  188. // x: 0.4,
  189. // y: 0.4,
  190. // r: 0.9,
  191. // colorStops: [{
  192. // offset: 0,
  193. // color: '#4E66B2'
  194. // }, {
  195. // offset: 1,
  196. // color: '#4E66B2'
  197. // }],
  198. // globalCoord: false
  199. // },
  200. // shadowColor: 'rgba(0, 0, 0, 0.5)',
  201. // shadowBlur: 2,
  202. // }
  203. // },
  204. // data: [
  205. // { name: '获奖', value: itemobj['获奖'], coord: [i, itemobj['获奖']] },
  206. // ]
  207. // },
  208. data: arr1
  209. },
  210. {
  211. name: legendData[1],
  212. type: "line",
  213. symbolSize: 10,
  214. symbol: 'circle',
  215. itemStyle: {
  216. normal: {
  217. color: "rgba(252,230,48,1)",
  218. barBorderRadius: 0,
  219. label: {
  220. show: true,
  221. position: "top",
  222. formatter: function (p) {
  223. return p.value > 0 ? (p.value) : '';
  224. }
  225. }
  226. }
  227. },
  228. data: arr2
  229. },
  230. {
  231. name: legendData[2],
  232. type: "line",
  233. symbolSize: 10,
  234. symbol: 'circle',
  235. itemStyle: {
  236. normal: {
  237. color: "#66FF33",
  238. barBorderRadius: 0,
  239. label: {
  240. show: true,
  241. position: "top",
  242. formatter: function (p) {
  243. return p.value > 0 ? (p.value) : '';
  244. }
  245. }
  246. }
  247. },
  248. data: arr3
  249. },
  250. {
  251. name: legendData[3],
  252. type: "line",
  253. symbolSize: 10,
  254. symbol: 'circle',
  255. itemStyle: {
  256. normal: {
  257. color: "#3366FF",
  258. barBorderRadius: 0,
  259. label: {
  260. show: true,
  261. position: "top",
  262. formatter: function (p) {
  263. return p.value > 0 ? (p.value) : '';
  264. }
  265. }
  266. }
  267. },
  268. data: arr4
  269. },
  270. {
  271. name: legendData[4],
  272. type: "line",
  273. symbolSize: 10,
  274. symbol: 'circle',
  275. itemStyle: {
  276. normal: {
  277. color: "#CC00FF",
  278. barBorderRadius: 0,
  279. label: {
  280. show: true,
  281. position: "top",
  282. formatter: function (p) {
  283. return p.value > 0 ? (p.value) : '';
  284. }
  285. }
  286. }
  287. },
  288. data: arr5
  289. },
  290. ]
  291. })
  292. }
  293. myChart.setOption(option)

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小小林熬夜学编程/article/detail/208743
推荐阅读