Device_StateCurve.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  1. <template>
  2. <div
  3. ref="statecurve"
  4. :class="className"
  5. :style="{ height: height, width: width }"
  6. ></div>
  7. </template>
  8. <script>
  9. import * as echarts from "echarts";
  10. export default {
  11. props: {
  12. defaul_tTime: {
  13. type: Array,
  14. },
  15. className: {
  16. type: String,
  17. default: "chart",
  18. },
  19. width: {
  20. type: String,
  21. default: "100%",
  22. },
  23. height: {
  24. type: String,
  25. default: "260px",
  26. },
  27. perData: {
  28. type: Array,
  29. default: () => [
  30. {
  31. color: "#01ACFF",
  32. name: "摄像头",
  33. value: [39],
  34. // nAmount: 566557.14,
  35. },
  36. ],
  37. },
  38. },
  39. data() {
  40. return {
  41. chart: null,
  42. color_XY: "rgba(0, 244, 253, 0.1)",
  43. itemStyle: [
  44. {
  45. normal: {
  46. borderColor: "rgba(0,244,253,1)",
  47. borderWidth: 2,
  48. color: "rgba(6, 68, 83, 1)",
  49. lineStyle: {
  50. width: 2, //折线宽度
  51. color: "rgba(0,244,253,1)",
  52. },
  53. },
  54. },
  55. {
  56. normal: {
  57. borderColor: "rgba(253,143,0,1)",
  58. borderWidth: 2,
  59. color: "rgba(6, 68, 83, 1)",
  60. lineStyle: {
  61. width: 2, //折线宽度
  62. color: "rgba(253,143,0,1)",
  63. },
  64. },
  65. },
  66. {
  67. normal: {
  68. borderColor: "rgba(0,255,18,1)",
  69. borderWidth: 2,
  70. color: "rgba(6, 68, 83, 1)",
  71. lineStyle: {
  72. width: 2, //折线宽度
  73. color: "rgba(0,255,18,1)",
  74. },
  75. },
  76. },
  77. ],
  78. msgFormSon: null,
  79. data_time: [],
  80. data: [],
  81. cont_time: 0,
  82. };
  83. },
  84. mounted() {
  85. // this.$nextTick(() => {
  86. // this.initChart();
  87. // // console.log(this.defaul_tTime);
  88. // });
  89. },
  90. beforeUnmount() {
  91. window.removeEventListener("resize", this.chart);
  92. },
  93. watch: {
  94. "$store.state.run_off_Status"() {
  95. // this.chart.resize();
  96. this.initChart();
  97. },
  98. },
  99. methods: {
  100. //次数分布折线图
  101. initChart() {
  102. var _this = this;
  103. var chart = echarts.init(this.$refs.statecurve);
  104. var time = _this.$store.state.Time_Data;
  105. var run_off_Status = _this.$store.state.run_off_Status;
  106. for (let i in run_off_Status) {
  107. if (run_off_Status[i].name === "runStates") {
  108. if (run_off_Status[i].list.length <= 0) {
  109. _this.data = [1, 1].map((val, ind) => {
  110. return [time[ind], val];
  111. });
  112. } else {
  113. _this.data = run_off_Status[i].list.map((val, ind) => {
  114. return [run_off_Status[i].listDate[ind], val];
  115. });
  116. }
  117. }
  118. run_off_Status[i].name === "offTime"
  119. ? (this.cont_time = run_off_Status[i].list)
  120. : "";
  121. }
  122. var option;
  123. option = {
  124. title: [
  125. {
  126. text: "运行状态曲线",
  127. left: "center",
  128. textStyle: {
  129. color: "#fff",
  130. fontSize: 14,
  131. },
  132. },
  133. {
  134. text: `OFF时长:${this.cont_time} 分钟`,
  135. left: "right",
  136. padding: [0, "7", 0, 0],
  137. textStyle: {
  138. color: "#fff",
  139. fontSize: 14,
  140. },
  141. },
  142. ],
  143. tooltip: {
  144. backgroundColor: "rgba(0, 244, 253, 0.1)",
  145. borderColor: "rgba(0, 244, 253, 0.3)",
  146. textStyle: {
  147. color: "#fff",
  148. },
  149. trigger: "axis",
  150. axisPointer: {
  151. type: "line",
  152. },
  153. formatter: function (params) {
  154. // console.log(params);
  155. var res = params[0].data[0];
  156. for (let i in params) {
  157. res += `
  158. <div style="display:flex">
  159. <div style="width:10px;height:10px;background:${
  160. params[i].color
  161. };border-radius: 10px;margin:10px 0;"></div>
  162. <div style="padding:4px 0px 0px 10px;">${
  163. params[i].seriesName
  164. }:</div>
  165. <div style="padding:4px 0px 0px 10px;">${
  166. params[i].data[1] == 1 ? "ON" : "OFF"
  167. }</div>
  168. </div>`; //可以在这个方法中做改变
  169. }
  170. return res;
  171. },
  172. },
  173. xAxis: {
  174. type: "time",
  175. boundaryGap: false,
  176. nameTextStyle: {
  177. // 名称样式
  178. fontSize: 12,
  179. color: "#fff",
  180. fontWeight: "bold",
  181. },
  182. axisLabel: {
  183. showMaxLabel: true,
  184. textStyle: {
  185. color: "#fff", //坐标值得具体的颜色
  186. },
  187. formatter: {
  188. year: "{MM}-{dd}\n{yyyy}",
  189. month: `{MM}-{dd}\n{yyyy}`,
  190. day: `{MM}-{dd}\n{yyyy}`,
  191. hour: "{HH}:{mm}\n{MM}-{dd}",
  192. minute: "{HH}:{mm}\n{MM}-{dd}",
  193. second: "{HH}:{mm}\n{MM}-{dd}",
  194. millisecond: "{HH}:{mm}\n{MM}-{dd}",
  195. none: "{yyyy}-{MM}-{dd} {hh}:{mm}:{ss}",
  196. },
  197. },
  198. axisLine: {
  199. lineStyle: {
  200. color: this.color_XY,
  201. },
  202. },
  203. },
  204. grid: {
  205. left: "3%",
  206. right: "4%",
  207. bottom: "10%",
  208. containLabel: true,
  209. },
  210. yAxis: {
  211. type: "value",
  212. splitNumber: 1,
  213. min: 0,
  214. max: 1,
  215. axisLabel: {
  216. formatter: function (value) {
  217. var texts = [];
  218. if (value == 0) {
  219. texts.push("OFF");
  220. } else {
  221. texts.push("ON");
  222. }
  223. return texts;
  224. },
  225. textStyle: {
  226. color: "#fff", //坐标值得具体的颜色
  227. },
  228. },
  229. splitLine: {
  230. lineStyle: {
  231. // 使用深浅的间隔色
  232. color: [this.color_XY],
  233. },
  234. },
  235. },
  236. series: [
  237. {
  238. name: "回路带电/停电",
  239. type: "line",
  240. // smooth: true,
  241. data: this.data,
  242. },
  243. ],
  244. };
  245. chart.setOption(option);
  246. window.addEventListener("resize", () => {
  247. chart.resize();
  248. });
  249. this.chart = chart;
  250. },
  251. },
  252. };
  253. </script>