JsonMarkerCharts.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <!--
  2. * @Author: your name
  3. * @Date: 2024-08-16 16:19:19
  4. * @LastEditTime: 2024-12-24 10:47:21
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/performance/components/JsonMarkerCharts.vue
  8. -->
  9. <template>
  10. <!-- json 数据渲染plotly散点图 废弃页面-->
  11. <div>
  12. <div ref="chart" style="width: 100%; height: 500px"></div>
  13. </div>
  14. </template>
  15. <script>
  16. import Plotly from "plotly.js-dist";
  17. import axios from "axios";
  18. export default {
  19. data() {
  20. return {
  21. dataArr: [], // 存储好点标识的数据
  22. dataBrr: [], // 存储坏点标识的数据
  23. dataCrr: [], // 存储限电点标识的数据
  24. };
  25. },
  26. async mounted() {
  27. try {
  28. // 从服务器获取数据
  29. const response = await axios.get(
  30. // "http://localhost:3006/wof053600062/WOF053600062-WOB00021/power_curve/manual/demo.json"
  31. "http://localhost:3006/getEchartsData"
  32. );
  33. this.processData(response.data); // 处理并分类数据
  34. this.initChart(); // 初始化图表
  35. } catch (error) {
  36. console.error("Error fetching data:", error);
  37. }
  38. },
  39. methods: {
  40. processData(data) {
  41. data.forEach((item) => {
  42. switch (item.lab) {
  43. case "1":
  44. this.dataArr.push({ x: item.wind_velocity, y: item.active_power });
  45. break;
  46. case "5":
  47. this.dataBrr.push({ x: item.wind_velocity, y: item.active_power });
  48. break;
  49. case "4":
  50. this.dataCrr.push({ x: item.wind_velocity, y: item.active_power });
  51. break;
  52. default:
  53. return;
  54. }
  55. });
  56. },
  57. initChart() {
  58. const chartElement = this.$refs.chart;
  59. const trace1 = {
  60. x: this.dataArr.map((d) => d.x),
  61. y: this.dataArr.map((d) => d.y),
  62. mode: "markers",
  63. marker: { color: "green" },
  64. name: "好点",
  65. };
  66. const trace2 = {
  67. x: this.dataBrr.map((d) => d.x),
  68. y: this.dataBrr.map((d) => d.y),
  69. mode: "markers",
  70. marker: { color: "red" },
  71. name: "坏点",
  72. };
  73. const trace3 = {
  74. x: this.dataCrr.map((d) => d.x),
  75. y: this.dataCrr.map((d) => d.y),
  76. mode: "markers",
  77. marker: { color: "blue" },
  78. name: "限电点",
  79. };
  80. const data = [trace1, trace2, trace3];
  81. const layout = {
  82. title: "Scatter Plot",
  83. xaxis: {
  84. title: "Wind Velocity",
  85. gridcolor: "rgb(255,255,255)",
  86. range: [1, 10],
  87. showgrid: true,
  88. showline: false,
  89. showticklabels: true,
  90. tickcolor: "rgb(127,127,127)",
  91. ticks: "outside",
  92. zeroline: false,
  93. },
  94. yaxis: {
  95. title: "Active Power",
  96. gridcolor: "rgb(255,255,255)",
  97. showgrid: true,
  98. showline: false,
  99. showticklabels: true,
  100. tickcolor: "rgb(127,127,127)",
  101. ticks: "outside",
  102. zeroline: false,
  103. },
  104. showlegend: true,
  105. hovermode: "closest",
  106. hovermode: "closest",
  107. paper_bgcolor: "rgb(255,255,255)",
  108. // plot_bgcolor: "rgb(229,229,229)",
  109. // paper_bgcolor: "lightgray", // 设置图表外部区域背景色
  110. plot_bgcolor: "#e5ecf6", // 设置绘图区背景色
  111. };
  112. Plotly.newPlot(chartElement, data, layout);
  113. // 响应窗口大小变化
  114. window.addEventListener("resize", () => {
  115. Plotly.Plots.resize(chartElement);
  116. });
  117. // 处理图表的选择事件
  118. chartElement.on("plotly_selected", (eventData) => {
  119. if (eventData) {
  120. const selectedPoints = [];
  121. eventData.points.forEach((pt) => {
  122. selectedPoints.push({
  123. x: pt.x,
  124. y: pt.y,
  125. curveNumber: pt.curveNumber,
  126. });
  127. });
  128. }
  129. });
  130. },
  131. },
  132. };
  133. </script>
  134. <style scoped>
  135. /* 自定义样式 */
  136. </style>