index4.vue 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <template>
  2. <el-row>
  3. <div id="index4" ref="echartD" style="width:110%;margin-left:-5%;height:110%;"></div>
  4. </el-row>
  5. </template>
  6. <script>
  7. import * as echarts from "echarts";
  8. export default {
  9. props: ["resData"],
  10. data() {
  11. return {};
  12. },
  13. watch: {
  14. resData() {
  15. this.getData();
  16. }
  17. },
  18. mounted() {
  19. this.getData();
  20. },
  21. methods: {
  22. getData() {
  23. let myChart = echarts.init(document.getElementById("index4"));
  24. let data = this.resData;
  25. let option = {
  26. legend: {
  27. itemGap: 20, // 图例每项之间的间隔。
  28. icon: "stack",
  29. right: 40,
  30. top:6,
  31. padding: 0, // 图例内边距
  32. textStyle: {
  33. color: "#000",
  34. align: "center"
  35. }
  36. },
  37. title: {
  38. x:'center',
  39. text: data[2].name,
  40. textStyle:{ //设置主标题风格
  41. color:data[2].color,//设置主标题字体颜色
  42. },
  43. },
  44. tooltip: {
  45. trigger: "axis",
  46. confine: true,
  47. textStyle: {
  48. fontSize: 12
  49. }
  50. },
  51. color: ["#FF0087" , "#80FFA5" ],
  52. xAxis: {
  53. show:true,//false
  54. boundaryGap:false,// true | ['30%', '20%'],x轴两边是否留白,true留白,false不留白
  55. axisLabel:{//x坐标轴刻度标签
  56. show:true,
  57. color:'#ccc',//'#ccc',设置标签颜色
  58. // rotate: -45,
  59. },
  60. axisLine:{//x坐标轴轴线
  61. show:true,
  62. lineStyle:{//x坐标轴轴线样式
  63. color:'#ccc',//'#ccc' | 'rgb(128, 128, 128)' | 'rgba(128, 128, 128, 0.5)',设置标签颜色
  64. }
  65. },
  66. data:data[3]
  67. },
  68. yAxis: [{
  69. // min:0, //取0为最小刻度
  70. // max: 100,
  71. name:"无\n线\n信\n号",
  72. type: 'value',
  73. splitLine:{
  74. show:false
  75. },
  76. nameLocation: 'left',
  77. nameTextStyle: {
  78. fontSize: 14,
  79. padding: [0, 80, 0, 0]
  80. },
  81. axisLine: {
  82. lineStyle: {
  83. type: 'solid' ,
  84. color: '#FF0087' , //左边线的颜色
  85. width: '1' //坐标线的宽度
  86. }
  87. },
  88. axisLabel: {
  89. textStyle: {
  90. color: '#FF0087' , //坐标值得具体的颜色
  91. }
  92. },
  93. }, {
  94. // min:0, //取0为最小刻度
  95. // max: 5,
  96. name:"剩\n余\n电\n量",
  97. type: 'value',
  98. splitLine:{
  99. show:false
  100. },
  101. nameLocation: 'left',
  102. nameTextStyle: {
  103. fontSize: 14,
  104. padding: [0, 0, 0, 80]
  105. },
  106. axisLine: {
  107. lineStyle: {
  108. type: 'solid' ,
  109. color: '#80FFA5' , //左边线的颜色
  110. width: '1' //坐标线的宽度
  111. }
  112. },
  113. axisLabel: {
  114. textStyle: {
  115. color: '#80FFA5' , //坐标值得具体的颜色
  116. }
  117. },
  118. }],
  119. series: [{
  120. name: "信号",
  121. type: 'line',
  122. stack: 'Total',
  123. smooth: true,
  124. axisLine: {
  125. lineStyle: {
  126. color: 'red',
  127. width: 0, //这里是为了突出显示加上的
  128. }
  129. },
  130. areaStyle: {
  131. opacity: 0.8,
  132. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  133. {
  134. offset: 0,
  135. color: 'rgb(128, 255, 165)'
  136. },
  137. {
  138. offset: 1,
  139. color: 'rgb(1, 191, 236)'
  140. }
  141. ])
  142. },
  143. showSymbol: false,
  144. emphasis: {
  145. focus: 'series'
  146. },
  147. data: data[1],
  148. yAxisIndex: 0, // 通过这个判断左右
  149. }, {
  150. name: "剩余电量",
  151. type: 'line',
  152. stack: 'Total',
  153. smooth: true,
  154. axisLine: {
  155. lineStyle: {
  156. color: '#ccc',
  157. width: 0, //这里是为了突出显示加上的
  158. }
  159. },
  160. areaStyle: {
  161. opacity: 0.8,
  162. color: new echarts.graphic.LinearGradient(0, 0, 0, 1, [
  163. {
  164. offset: 0,
  165. color: 'rgb(255, 0, 135)'
  166. },
  167. {
  168. offset: 1,
  169. color: 'rgb(135, 0, 157)'
  170. }
  171. ])
  172. },
  173. showSymbol: false,
  174. emphasis: {
  175. focus: 'series'
  176. },
  177. data: data[0],
  178. yAxisIndex: 1,
  179. }]
  180. };
  181. myChart.setOption(option);
  182. window.addEventListener("resize", function() {
  183. myChart.resize();
  184. });
  185. }
  186. }
  187. };
  188. </script>
  189. <style lang="scss" scoped></style>