PlotlyCharts.vue 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. <template>
  2. <div>
  3. <!-- 总图组件 -->
  4. <div
  5. v-if="comType === 'generalDrawing'"
  6. id="power-curve-plot"
  7. style="width: 100%; height: 550px"
  8. ></div>
  9. <!-- 分图组件 -->
  10. <template v-else-if="comType === 'graph'">
  11. <div id="chart-" style="width: 100%; height: 550px"></div>
  12. </template>
  13. </div>
  14. </template>
  15. <script>
  16. import Plotly from "plotly.js-dist";
  17. export default {
  18. props: {
  19. lineMarkerData: Object,
  20. comType: String,
  21. },
  22. name: "PowerCurvePlot",
  23. data() {
  24. return {
  25. graphData: [], //分图数据length data
  26. config: {
  27. powerConfig: {
  28. mode: "lines+markers",
  29. name: "合同功率曲线",
  30. line: { color: "red" },
  31. marker: { color: "red", size: 5 },
  32. },
  33. lableConfig: {
  34. title: { text: "", x: 0.5 },
  35. plot_bgcolor: "#e5ecf6", // Chart background color
  36. xaxis: {
  37. title: "风速(m/s)",
  38. // range: [0, 26],
  39. tickmode: "linear",
  40. gridcolor: "rgb(255,255,255)",
  41. showgrid: true,
  42. zeroline: false,
  43. tickcolor: "rgb(255,255,255)",
  44. dtick: 1,
  45. tickangle: -45,
  46. },
  47. yaxis: {
  48. title: "功率(kW)",
  49. gridcolor: "rgb(255,255,255)",
  50. showgrid: true,
  51. zeroline: false,
  52. tickcolor: "rgb(255,255,255)",
  53. },
  54. legend: {
  55. orientation: "h",
  56. xanchor: "center",
  57. x: 0.5,
  58. y: -0.2,
  59. },
  60. },
  61. colors: [
  62. "#636EFA",
  63. "#EF553B",
  64. "#00CC96",
  65. "#AB63FA",
  66. "#FFA15A",
  67. "#19D3F3",
  68. "#FF6692",
  69. "#B6E880",
  70. "#FF97FF",
  71. "#FECB52",
  72. "#636EFB",
  73. "#EF553C",
  74. "#00CC97",
  75. "#AB63FB",
  76. "#FFA15B",
  77. "#19D3F4",
  78. "#FF6693",
  79. "#B6E881",
  80. "#FF97FE",
  81. "#FECB51",
  82. "#1F77B4",
  83. "#FF7F0E",
  84. "#2CA02C",
  85. "#D62728",
  86. "#9467BD",
  87. "#8C564B",
  88. "#E377C2",
  89. "#7F7F7F",
  90. "#BCBD22",
  91. "#17BECF",
  92. "#1A55F2",
  93. "#FF5733",
  94. "#33FF57",
  95. "#3375FF",
  96. "#FF33A6",
  97. "#57FF33",
  98. "#3380FF",
  99. "#FF8033",
  100. "#57FF80",
  101. "#8033FF",
  102. "#FF3380",
  103. "#FFD733",
  104. ],
  105. },
  106. powerCurveData: {
  107. turbines: [],
  108. contractPowerCurve: [],
  109. },
  110. };
  111. },
  112. mounted() {
  113. this.updateCharts(); // 初次渲染
  114. },
  115. watch: {
  116. lineMarkerData: {
  117. deep: true,
  118. handler() {
  119. this.updateCharts(); // 数据变化时更新
  120. },
  121. },
  122. comType(newType, oldType) {
  123. if (newType !== oldType) {
  124. this.updateCharts(); // 类型变化时更新
  125. }
  126. },
  127. },
  128. methods: {
  129. updateCharts() {
  130. this.powerCurveData.turbines =
  131. this.lineMarkerData.data?.filter(
  132. (item) => item.enginName !== "合同功率曲线"
  133. ) || [];
  134. this.powerCurveData.contractPowerCurve =
  135. this.lineMarkerData.data?.filter(
  136. (item) => item.enginName === "合同功率曲线"
  137. ) || [];
  138. if (this.comType === "generalDrawing" && this.lineMarkerData?.data) {
  139. this.renderPlot();
  140. } else if (this.comType === "graph" && this.lineMarkerData?.data) {
  141. this.$nextTick(() => {
  142. this.initializeEngineCharts();
  143. });
  144. }
  145. },
  146. renderPlot() {
  147. const data = [];
  148. // Add traces for each turbine with colors from config
  149. this.powerCurveData.turbines.forEach((turbine, index) => {
  150. data.push({
  151. x: turbine.xData,
  152. y: turbine.yData.map((val) => (val !== null ? val : 0.0)),
  153. mode: "lines",
  154. name: turbine.enginName,
  155. line: {
  156. color: this.config.colors[index % this.config.colors.length],
  157. },
  158. });
  159. });
  160. data.push({
  161. x: this.powerCurveData.contractPowerCurve[0].xData,
  162. y: this.powerCurveData.contractPowerCurve[0].yData,
  163. mode: this.config.powerConfig.mode,
  164. name: this.config.powerConfig.name,
  165. line: this.config.powerConfig.line,
  166. marker: this.config.powerConfig.marker,
  167. });
  168. const layout = {
  169. title: this.config.lableConfig.title.text || "有功功率曲线分析",
  170. plot_bgcolor: this.config.lableConfig.plot_bgcolor,
  171. xaxis: this.config.lableConfig.xaxis,
  172. yaxis: this.config.lableConfig.yaxis,
  173. legend: this.config.lableConfig.legend,
  174. };
  175. Plotly.newPlot("power-curve-plot", data, layout);
  176. },
  177. //初始化分图
  178. //初始化分图
  179. initializeEngineCharts() {
  180. const fentuCharts = this.powerCurveData.turbines.filter(
  181. (item) =>
  182. item.enginCode === this.lineMarkerData?.formInfoFieldEngineCode ||
  183. item.enginName === this.lineMarkerData?.formInfoFieldEngineCode
  184. );
  185. const data = [];
  186. const layout = {
  187. title:
  188. fentuCharts[0].enginName ||
  189. fentuCharts[0].enginCode + "风机有功功率曲线分析",
  190. plot_bgcolor: this.config.lableConfig.plot_bgcolor,
  191. xaxis: this.config.lableConfig.xaxis,
  192. yaxis: this.config.lableConfig.yaxis,
  193. legend: this.config.lableConfig.legend,
  194. };
  195. this.powerCurveData.turbines.forEach((turbine, index) => {
  196. data.push({
  197. x: turbine.xData,
  198. y: turbine.yData.map((val) => (val !== null ? val : 0.0)),
  199. mode: "lines",
  200. name: turbine.enginName,
  201. line: {
  202. color:
  203. turbine?.enginCode ===
  204. this.lineMarkerData?.formInfoFieldEngineCode ||
  205. turbine?.enginName ===
  206. this.lineMarkerData?.formInfoFieldEngineCode
  207. ? "#1c77b3"
  208. : "#d3d3d3",
  209. },
  210. });
  211. });
  212. data.push({
  213. x: this.powerCurveData.contractPowerCurve[0].xData,
  214. y: this.powerCurveData.contractPowerCurve[0].yData,
  215. mode: "lines+markers",
  216. name: this.powerCurveData.contractPowerCurve[0].enginName,
  217. line: {
  218. color: "red",
  219. },
  220. });
  221. Plotly.newPlot("chart-", data, layout);
  222. },
  223. },
  224. };
  225. </script>
  226. <style scoped>
  227. /* You can add styles for your component here */
  228. </style>