histTrendChart.vue 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <template>
  2. <div ref="histTrendChart" style="width: 100%; height: 100%"></div>
  3. </template>
  4. <script>
  5. import * as echarts from "echarts";
  6. import api from "@/api/Overview/index";
  7. import { ElMessage } from "element-plus";
  8. export default {
  9. props: {
  10. msg: Object,
  11. filterSec_value: Object,
  12. hisDefaultTime: Object,
  13. },
  14. data() {
  15. return {
  16. yName: "",
  17. };
  18. },
  19. mounted() {
  20. this.$nextTick(() => {
  21. this.electricIco();
  22. });
  23. },
  24. beforeUnmount() {
  25. window.removeEventListener("resize", this.chart);
  26. },
  27. watch: {
  28. "$store.state.siteId"() {
  29. this.electricIco();
  30. },
  31. hisDefaultTime() {
  32. this.electricIco();
  33. },
  34. msg() {
  35. this.electricIco();
  36. },
  37. filterSec_value() {
  38. this.electricIco();
  39. },
  40. },
  41. methods: {
  42. electricIco() {
  43. this.$store.commit("TimeAll_function", [this.hisDefaultTime]);
  44. var time = this.$store.state.Time_Data;
  45. // console.log('time[0]')
  46. // console.log(time[0])
  47. // console.log(time[1])
  48. api
  49. .electricIco({
  50. siteId: this.$store.state.siteId,
  51. date: time[0],
  52. })
  53. .then((requset) => {
  54. if (requset.status === "SUCCESS") {
  55. this.initChart(requset.data);
  56. } else {
  57. ElMessage.success({
  58. message: requset.msg,
  59. type: "success",
  60. });
  61. }
  62. });
  63. },
  64. //次数分布折线图
  65. initChart(data) {
  66. var chart = echarts.init(this.$refs.histTrendChart);
  67. var option;
  68. var dataAll = [];
  69. data.map((val) => {
  70. let valName=val.name.charAt(0) + val.name.slice(1).toLowerCase() //首字母大写
  71. if (this.msg == 0) {
  72. this.yName = "A";
  73. if (val.name == "IA" || val.name == "IB" || val.name == "IC") {
  74. return dataAll.push({
  75. name: valName + "(A)",
  76. type: "line",
  77. smooth: false,
  78. data: val.list,
  79. symbolSize: 6,
  80. });
  81. }
  82. } else {
  83. this.yName = "kV";
  84. if (val.name == "UA" || val.name == "UB" || val.name == "UC") {
  85. return dataAll.push({
  86. name: val.name + "(kV)",
  87. type: "line",
  88. smooth: false,
  89. data: val.list,
  90. symbolSize: 6,
  91. });
  92. }
  93. }
  94. });
  95. // console.log(JSON.stringify(data),JSON.stringify(dataAll));
  96. option = {
  97. color: ["#FEB70D", "#50F335", "#0DC8FE"],
  98. tooltip: {
  99. trigger: "axis",
  100. },
  101. // 图列组件
  102. legend: {
  103. itemHeight: 10, //改变圆圈大小
  104. itemWidth: 26, //改变圆圈大小
  105. itemGap: 30,
  106. textStyle: {
  107. color: "#fff",
  108. },
  109. left: "30%",
  110. bottom: "0",
  111. },
  112. grid: {
  113. left: "0%",
  114. right: "0%",
  115. bottom: "15%",
  116. top: "20%",
  117. containLabel: true,
  118. },
  119. xAxis: {
  120. type: "category",
  121. boundaryGap: true,
  122. data: data[0].listDate.map((val) => {
  123. return val.split(":")[0] + ":" + val.split(":")[1];
  124. }),
  125. axisTick: {
  126. show: false, //去除刻度线
  127. },
  128. axisLabel: {
  129. color: "#fff", // 文本颜色
  130. },
  131. axisLine: {
  132. show: false, // 去除轴线
  133. },
  134. },
  135. yAxis: {
  136. name: this.yName,
  137. nameTextStyle: {
  138. color: "#fff",
  139. fontSize: 10,
  140. },
  141. type: "value",
  142. axisTick: {
  143. show: false, //去除刻度线
  144. },
  145. axisLabel: {
  146. color: "#fff", // 文本颜色
  147. },
  148. axisLine: {
  149. show: false, // 去除轴线
  150. },
  151. splitNumber: 5,
  152. splitLine: {
  153. show: true,
  154. lineStyle: {
  155. color: "rgba(255,255,255,0.1)",
  156. },
  157. },
  158. },
  159. series: dataAll,
  160. };
  161. chart.setOption(option, true);
  162. window.addEventListener("resize", () => {
  163. chart.resize();
  164. });
  165. this.chart = chart;
  166. },
  167. },
  168. };
  169. </script>