timedomaincharts.vue 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296
  1. <template>
  2. <div>
  3. <div class="FD">
  4. <div v-if="TZshow" class="eigenvalue">
  5. <h5>特征值</h5>
  6. <p>有效值:{{ this.timeList.Xrms }}</p>
  7. <p>平均值:{{ this.timeList.mean_value }}</p>
  8. <p>最大值:{{ this.timeList.max_value }}</p>
  9. <p>最小值:{{ this.timeList.min_value }}</p>
  10. <p>峰值:{{ this.timeList.Xp }}</p>
  11. <p>峰峰值:{{ this.timeList.Xpp }}</p>
  12. <p>波形因子:{{ this.timeList.Sf }}</p>
  13. <p>脉冲指标:{{ this.timeList.If }}</p>
  14. <p>裕度指标:{{ this.timeList.Ce }}</p>
  15. <p>偏度指标:{{ this.timeList.Cw }}</p>
  16. <p>峭度指标:{{ this.timeList.Cq }}</p>
  17. </div>
  18. </div>
  19. <!-- ECharts 图表容器 -->
  20. <div class="line-chart" ref="chart" v-loading="loadingTime"></div>
  21. </div>
  22. </template>
  23. <script>
  24. import axios from "axios";
  25. import * as echarts from "echarts"; // 导入 echarts 库
  26. export default {
  27. name: "TimedomainCharts", // 组件名称
  28. props: {
  29. currentIndex: {
  30. type: Number,
  31. default: 0,
  32. },
  33. activeIndex: {
  34. type: Number,
  35. default: 0,
  36. },
  37. loadingTime: {
  38. type: Boolean,
  39. default: false,
  40. },
  41. ids: {
  42. type: Array,
  43. default: () => [],
  44. },
  45. timeListTwo: {
  46. type: Object,
  47. default: () => ({}),
  48. },
  49. currentRow: {
  50. type: Object,
  51. default: () => ({}),
  52. },
  53. windCode: {
  54. type: String,
  55. default: "",
  56. },
  57. },
  58. data() {
  59. return {
  60. chartInstance: null,
  61. option: null,
  62. TZshow: false,
  63. timeList: {},
  64. };
  65. },
  66. watch: {
  67. // 监听 chartData 和 chartLabels 的变化,重新绘制图表
  68. chartData(newData) {
  69. this.updateChart(newData, this.chartLabels);
  70. },
  71. chartLabels(newLabels) {
  72. this.updateChart(this.chartData, newLabels);
  73. },
  74. timeListTwo(newValue) {
  75. this.timeList = newValue; // 将 timeListTwo 的新值赋给 timeList
  76. if (this.chartInstance) {
  77. this.updateChart(this.timeList.y, this.timeList.x); // 更新图表
  78. }
  79. },
  80. // 监听 timeList 的变化
  81. timeList: {
  82. handler(newValue) {
  83. if (this.chartInstance) {
  84. this.updateChart(newValue.y, newValue.x); // 只在 chartInstance 初始化后更新图表
  85. }
  86. },
  87. deep: true, // 深度监听
  88. },
  89. },
  90. mounted() {
  91. this.$nextTick(() => {
  92. setTimeout(() => {
  93. this.initializeChart(); // 延迟2秒后调用
  94. this.getTime();
  95. }, 500); // 2000毫秒,即2秒
  96. });
  97. },
  98. methods: {
  99. initializeChart() {
  100. const chartDom = this.$refs.chart;
  101. if (chartDom && !this.chartInstance) {
  102. this.chartInstance = echarts.init(chartDom);
  103. }
  104. if (this.timeList.y && this.timeList.x) {
  105. this.updateChart(this.timeList.y, this.timeList.x);
  106. }
  107. },
  108. // 更新图表数据
  109. updateChart(data, labels) {
  110. if (!this.chartInstance) return; // Check if chartInstance is available
  111. const maxX = Math.max(...labels);
  112. const maxAxisValue = Math.ceil(maxX / 5) * 5;
  113. const ticks = [];
  114. for (let i = 0; i <= maxAxisValue; i += 5) {
  115. ticks.push(i);
  116. }
  117. const option = {
  118. title: {
  119. text: this.timeList.title,
  120. left: "center",
  121. },
  122. toolbox: {
  123. feature: {
  124. dataZoom: { yAxisIndex: "none" },
  125. restore: {},
  126. saveAsImage: {},
  127. myCustomTool: {
  128. show: true,
  129. title: "上一条",
  130. icon: `image://${require("@/assets/analyse/08.png")}`,
  131. onclick: () => this.previousRow(),
  132. },
  133. myCustomTool2: {
  134. show: true,
  135. title: "下一条",
  136. icon: `image://${require("@/assets/analyse/09.png")}`,
  137. onclick: () => this.nextRow(),
  138. },
  139. myCustomTool3: {
  140. show: true,
  141. title: "特征值",
  142. icon: `image://${require("@/assets/analyse/10.png")}`,
  143. onclick: () => this.Show(),
  144. },
  145. },
  146. },
  147. xAxis: {
  148. type: "value",
  149. name: this.timeList.xaxis,
  150. nameLocation: "center",
  151. nameTextStyle: {
  152. fontSize: 14,
  153. color: "#333",
  154. padding: [10, 0, 0, 0],
  155. },
  156. axisLabel: {
  157. formatter: (value) => {
  158. return value;
  159. },
  160. },
  161. axisTick: {
  162. show: true,
  163. },
  164. axisLine: {
  165. show: true,
  166. },
  167. data: ticks,
  168. },
  169. yAxis: {
  170. type: "value",
  171. name: this.timeList.yaxis,
  172. // nameLocation: "center",
  173. nameTextStyle: {
  174. fontSize: 14,
  175. color: "#333",
  176. padding: [10, 0, 0, 0],
  177. },
  178. axisLabel: {
  179. formatter: (value) => {
  180. return value;
  181. },
  182. },
  183. axisTick: {
  184. show: true,
  185. },
  186. axisLine: {
  187. show: true,
  188. },
  189. },
  190. tooltip: {
  191. trigger: "axis",
  192. formatter: (params) => {
  193. const xValue = params[0].value[0];
  194. const yValue = params[0].value[1];
  195. return `X: ${xValue}<br/>Y: ${yValue}`;
  196. },
  197. axisPointer: {
  198. type: "line",
  199. },
  200. },
  201. series: [
  202. {
  203. name: "数据系列",
  204. type: "line",
  205. data: labels.map((item, index) => [item, data[index]]),
  206. symbol: "none",
  207. symbolSize: 8,
  208. lineStyle: {
  209. color: "#162961",
  210. width: 1,
  211. },
  212. itemStyle: {
  213. color: "#162961",
  214. borderColor: "#fff",
  215. borderWidth: 1,
  216. },
  217. },
  218. ],
  219. };
  220. this.chartInstance.setOption(option);
  221. },
  222. getTime() {
  223. this.$emit("handleLoading", null, true, this.activeIndex);
  224. const params = {
  225. ids: this.ids,
  226. windCode: "SKF001",
  227. analysisType: "time",
  228. // windCode: this.windCode,
  229. };
  230. axios
  231. .post("/WJapi/analysis/time", params)
  232. .then((res) => {
  233. this.timeList = JSON.parse(res.data);
  234. })
  235. .catch((error) => {})
  236. .finally(() => {
  237. this.$emit("handleLoading", this.currentRow, false, this.activeIndex);
  238. });
  239. },
  240. previousRow() {
  241. this.$emit("update-previous-row", 1, this.activeIndex);
  242. },
  243. // 触发下一条
  244. nextRow() {
  245. this.$emit("update-next-row", 1, this.activeIndex);
  246. },
  247. Show() {
  248. this.TZshow = !this.TZshow;
  249. },
  250. },
  251. };
  252. </script>
  253. <style lang="scss" scoped>
  254. .line-chart {
  255. width: 100%;
  256. height: 280px;
  257. }
  258. .FD {
  259. width: 100%;
  260. height: 1px;
  261. position: relative;
  262. }
  263. .eigenvalue {
  264. position: absolute;
  265. top: 30px;
  266. right: 0;
  267. font-size: 10px;
  268. width: 100px;
  269. border: 1px solid black;
  270. padding: 5px;
  271. background: #fff;
  272. z-index: 99;
  273. h5 {
  274. line-height: 16px;
  275. height: 16px;
  276. }
  277. }
  278. </style>