timedomaincharts.vue 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  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"></div>
  21. </div>
  22. </template>
  23. <script>
  24. import * as echarts from "echarts"; // 导入 echarts 库
  25. export default {
  26. name: "TimedomainCharts", // 组件名称
  27. props: {
  28. currentIndex: {
  29. type: Number,
  30. default: 0,
  31. },
  32. timeList: {
  33. type: Object,
  34. default: () => ({}),
  35. },
  36. },
  37. data() {
  38. return {
  39. chartInstance: null,
  40. option: null,
  41. TZshow: false,
  42. };
  43. },
  44. watch: {
  45. // 监听 chartData 和 chartLabels 的变化,重新绘制图表
  46. chartData(newData) {
  47. this.updateChart(newData, this.chartLabels);
  48. },
  49. chartLabels(newLabels) {
  50. this.updateChart(this.chartData, newLabels);
  51. },
  52. },
  53. mounted() {
  54. this.$nextTick(() => {
  55. this.initializeChart();
  56. });
  57. },
  58. methods: {
  59. initializeChart() {
  60. // 获取图表容器
  61. const chartDom = this.$refs.chart;
  62. // 初始化图表实例
  63. this.chartInstance = echarts.init(chartDom);
  64. // 默认图表数据和配置
  65. const defaultData = this.timeList.y;
  66. const defaultLabels = this.timeList.x;
  67. this.updateChart(defaultData, defaultLabels);
  68. },
  69. // 更新图表数据
  70. updateChart(data, labels) {
  71. const option = {
  72. title: {
  73. text: this.timeList.title,
  74. left: "center",
  75. },
  76. toolbox: {
  77. feature: {
  78. dataZoom: { yAxisIndex: "none" },
  79. restore: {},
  80. saveAsImage: {},
  81. myCustomTool: {
  82. show: true,
  83. title: "上一条",
  84. icon: `image://${require("@/assets/analyse/08.png")}`,
  85. onclick: () => this.previousRow(),
  86. },
  87. myCustomTool2: {
  88. show: true,
  89. title: "下一条",
  90. icon: `image://${require("@/assets/analyse/09.png")}`,
  91. onclick: () => this.nextRow(),
  92. },
  93. myCustomTool3: {
  94. show: true,
  95. title: "特征值",
  96. icon: `image://${require("@/assets/analyse/10.png")}`,
  97. onclick: () => this.Show(),
  98. },
  99. },
  100. },
  101. xAxis: {
  102. type: "category",
  103. name: this.timeList.xaxis, // 设置X轴标题
  104. nameLocation: "center", // 标题位置:可选 "start" | "center" | "end"
  105. nameTextStyle: {
  106. fontSize: 14,
  107. color: "#333", // 标题颜色
  108. padding: [10, 0, 0, 0], // 上、右、下、左的间距
  109. },
  110. data: labels, // 横坐标数据
  111. boundaryGap: false, // 坐标轴是否留白
  112. position: "bottom", // 确保X轴在底部
  113. },
  114. yAxis: {
  115. type: "value",
  116. name: this.timeList.yaxis,
  117. },
  118. tooltip: {
  119. trigger: "axis",
  120. axisPointer: {
  121. type: "line", // 显示十字线
  122. },
  123. },
  124. series: [
  125. {
  126. name: "数据系列",
  127. type: "line", // 折线图
  128. data: data, // 数据
  129. symbol: "none", // 数据点的样式
  130. symbolSize: 8, // 数据点的大小
  131. lineStyle: {
  132. color: "rgb(75, 192, 192)", // 折线颜色
  133. width: 2, // 线条宽度
  134. },
  135. itemStyle: {
  136. color: "rgb(75, 192, 192)", // 数据点颜色
  137. borderColor: "#fff",
  138. borderWidth: 2,
  139. },
  140. },
  141. ],
  142. };
  143. // 使用更新的配置更新图表
  144. this.chartInstance.setOption(option);
  145. },
  146. previousRow() {
  147. },
  148. nextRow() {
  149. },
  150. Show() {
  151. this.TZshow = !this.TZshow;
  152. },
  153. },
  154. };
  155. </script>
  156. <style lang="scss" scoped>
  157. .line-chart {
  158. width: 100%;
  159. height: 250px;
  160. }
  161. .FD {
  162. width: 100%;
  163. height: 1px;
  164. position: relative;
  165. }
  166. .eigenvalue {
  167. position: absolute;
  168. top: 30px;
  169. right: 0;
  170. font-size: 10px;
  171. width: 100px;
  172. border: 1px solid black;
  173. padding: 5px;
  174. background: #fff;
  175. z-index: 99;
  176. h5 {
  177. line-height: 16px;
  178. height: 16px;
  179. }
  180. }
  181. </style>