FaultUnit.vue 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. <!--
  2. * @Author: your name
  3. * @Date: 2025-01-15 15:49:57
  4. * @LastEditTime: 2025-01-23 09:56:11
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/performance/components/chartsCom/FaultUntal.vue
  8. -->
  9. <template>
  10. <div>
  11. <div ref="chart" style="width: 100%; height: 400px"></div>
  12. </div>
  13. </template>
  14. <script>
  15. import Plotly from "plotly.js-dist";
  16. export default {
  17. name: "faultAll",
  18. props: {
  19. faultTypes: {
  20. type: Array,
  21. default: [],
  22. }, // 故障机组
  23. faultCounts: {
  24. type: Array,
  25. default: [],
  26. }, // 故障次数
  27. faultDurations: {
  28. type: Array,
  29. default: [],
  30. }, // 故障时长
  31. fenFaultCsvData: {
  32. type: Array,
  33. default: [],
  34. },
  35. },
  36. watch: {
  37. faultCounts: {
  38. deep: true,
  39. handler(v) {
  40. console.log(this.faultDurations, this.faultTypes);
  41. this.renderChart();
  42. },
  43. },
  44. },
  45. mounted() {
  46. this.renderChart();
  47. },
  48. methods: {
  49. renderChart() {
  50. // 故障次数的散点图数据(左侧 Y 轴)
  51. const scatterFaultCounts = {
  52. x: this.faultTypes.slice(0, 10),
  53. y: this.faultCounts.slice(0, 10),
  54. mode: "markers", // 散点图
  55. marker: { color: "#64ADC2", size: 10 }, // 蓝色散点
  56. name: "故障次数",
  57. };
  58. // 故障时长的散点图数据(右侧 Y 轴)
  59. const scatterFaultDurations = {
  60. x: this.faultTypes.slice(0, 10),
  61. y: this.faultDurations.slice(0, 10),
  62. mode: "markers", // 散点图
  63. marker: { color: "#1A295D", size: 10 }, // 红色散点
  64. name: "故障时长",
  65. yaxis: "y2", // 使用第二个 Y 轴(右侧)
  66. };
  67. // 布局配置,设置双 Y 轴
  68. const layout = {
  69. title: "机组故障次数与时长分析Top10",
  70. xaxis: {
  71. title: "故障机组",
  72. tickangle: 30,
  73. tickmode: "array",
  74. tickvals: this.faultTypes.slice(0, 10), // 保证这里是字符串数组
  75. ticktext: this.faultTypes.slice(0, 10), // 确保 ticktext 使用相同的标签
  76. tickfont: { size: 12 },
  77. },
  78. yaxis: {
  79. title: "故障次数",
  80. titlefont: { color: "#64ADC2" },
  81. tickfont: { color: "#64ADC2" },
  82. side: "left", // 左侧的 Y 轴
  83. showline: true,
  84. linecolor: "#64ADC2",
  85. },
  86. yaxis2: {
  87. title: "故障时长(秒)",
  88. titlefont: { color: "#1A295D" },
  89. tickfont: { color: "#1A295D" },
  90. overlaying: "y", // 在第一个 Y 轴上方绘制
  91. side: "right", // 右侧的 Y 轴
  92. position: 1, // 调整右侧轴的位置
  93. showline: true,
  94. // tickvals: this.faultTypes.slice(0, 10), // 保证这里是字符串数组
  95. // ticktext: this.faultTypes.slice(0, 10), // 确保 ticktext 使用相同的标签
  96. linecolor: "#1A295D", // 设置右侧轴线颜色
  97. },
  98. showlegend: false, // 显示图例
  99. margin: {
  100. t: 80, // 上边距
  101. b: 150, // 下边距,给 X 轴标签更多空间
  102. },
  103. };
  104. // 渲染图表
  105. Plotly.newPlot(
  106. this.$refs.chart,
  107. [scatterFaultCounts, scatterFaultDurations],
  108. layout
  109. );
  110. },
  111. },
  112. };
  113. </script>
  114. <style scoped>
  115. /* 你可以根据需要添加样式 */
  116. </style>