line4.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. layui.use(['echarts'], function() {
  2. let echarts = layui.echarts;
  3. var line4 = echarts.init(document.getElementById('line4'),null, {
  4. width: 600,
  5. height: 400
  6. });
  7. const colorList = ["#9E87FF", '#73DDFF', '#fe9a8b', '#F56948', '#9E87FF']
  8. option = {
  9. title: {
  10. text: '用电量'
  11. },
  12. tooltip: {
  13. trigger: 'axis'
  14. },
  15. legend: {
  16. data: ['2018', '2019']
  17. },
  18. grid: {
  19. left: '3%',
  20. right: '4%',
  21. bottom: '3%',
  22. containLabel: true
  23. },
  24. toolbox: {
  25. feature: {
  26. saveAsImage: {}
  27. }
  28. },
  29. xAxis: {
  30. type: 'category',
  31. boundaryGap: false,//坐标轴两边留白
  32. data: ['12201', '12202', '12203','12204','12301','12302','12303','12304','12401', '12402', '12403','12404'],
  33. axisLabel: { //坐标轴刻度标签的相关设置。
  34. interval: 0,//设置为 1,表示『隔一个标签显示一个标签』
  35. // margin:15,
  36. color: '#1B253A',
  37. fontStyle: 'normal',
  38. fontFamily: '微软雅黑',
  39. fontSize: 12,
  40. formatter:function(params) {
  41. var newParamsName = "";
  42. var paramsNameNumber = params.length;
  43. var provideNumber = 4; //一行显示几个字
  44. var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
  45. if (paramsNameNumber > provideNumber) {
  46. for (var p = 0; p < rowNumber; p++) {
  47. var tempStr = "";
  48. var start = p * provideNumber;
  49. var end = start + provideNumber;
  50. if (p == rowNumber - 1) {
  51. tempStr = params.substring(start, paramsNameNumber);
  52. } else {
  53. tempStr = params.substring(start, end) + "\n";
  54. }
  55. newParamsName += tempStr;
  56. }
  57. } else {
  58. newParamsName = params;
  59. }
  60. return newParamsName
  61. },
  62. //rotate:50,
  63. },
  64. axisTick:{//坐标轴刻度相关设置。
  65. show: false,
  66. },
  67. axisLine:{//坐标轴轴线相关设置
  68. lineStyle:{
  69. color:'#E5E9ED',
  70. // opacity:0.2
  71. }
  72. },
  73. splitLine: { //坐标轴在 grid 区域中的分隔线。
  74. show: true,
  75. lineStyle: {
  76. color: '#E5E9ED',
  77. // opacity:0.1
  78. }
  79. }
  80. },
  81. yAxis: [
  82. {
  83. type: 'value',
  84. splitNumber: 5,
  85. axisLabel: {
  86. color: '#a8aab0',
  87. fontStyle: 'normal',
  88. fontFamily: '微软雅黑',
  89. fontSize: 12
  90. },
  91. axisLine:{
  92. show: false
  93. },
  94. axisTick:{
  95. show: false
  96. },
  97. splitLine: {
  98. show: true,
  99. lineStyle: {
  100. color: '#E5E9ED',
  101. // opacity:0.1
  102. }
  103. }
  104. }
  105. ],
  106. series: [
  107. {
  108. name: '2018',
  109. type: 'line',
  110. itemStyle: {
  111. color:'#3A84FF',
  112. lineStyle: {
  113. color: "#3A84FF",
  114. width:1
  115. },
  116. areaStyle: {
  117. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
  118. offset: 0,
  119. color: 'rgba(58,132,255,0)'
  120. }, {
  121. offset: 1,
  122. color: 'rgba(58,132,255,0.35)'
  123. }]),
  124. }
  125. },
  126. data: [ 1, 2, 3, 3, 5, 6, 5, 3, 6, 5, 5, 4]
  127. },
  128. {
  129. name: '2019',
  130. type: 'line',
  131. itemStyle: {
  132. color:'rgba(255,80,124,1)',
  133. lineStyle: {
  134. color: "rgba(255,80,124,1)",
  135. width:1
  136. },
  137. areaStyle: {
  138. color: new echarts.graphic.LinearGradient(0, 1, 0, 0, [{
  139. offset: 0,
  140. color: 'rgba(255,80,124,0)'
  141. }, {
  142. offset: 1,
  143. color: 'rgba(255,80,124,0.35)'
  144. }]),
  145. }
  146. },
  147. data: [9, 5,7,8,6,7,8,7,7,6,8,6]
  148. }
  149. ]
  150. };
  151. line4.setOption(option);
  152. window.onresize = function() {
  153. line4.resize();
  154. }
  155. })