BoxMarkersCharts.vue 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <!--
  2. * @Author: your name
  3. * @Date: 2024-09-11 14:36:31
  4. * @LastEditTime: 2025-01-21 18:55:00
  5. * @LastEditors: bogon
  6. * @Description: In User Settings Edit
  7. * @FilePath: /performance-test/src/views/performance/components/chartsCom/BoxMarkersCharts.vue
  8. -->
  9. <!-- <template>
  10. <div> -->
  11. <!-- BoxMarkersCharts
  12. <h1>叶尖速比时序分析</h1>
  13. <h1>风能利用系数时序分析</h1> -->
  14. <!-- <div :id="`chart-${inds}`" style="width: 100%; height: 550px"></div>
  15. </div>
  16. </template>
  17. -->
  18. <template>
  19. <div>
  20. <div
  21. v-loading="loading"
  22. ref="plotlyChart"
  23. style="width: 100%; height: 450px"
  24. >
  25. <el-empty v-if="isError" description="请求失败"></el-empty>
  26. </div>
  27. </div>
  28. </template>
  29. <script>
  30. import Plotly from "plotly.js-dist-min";
  31. import axios from "axios";
  32. import { myMixin } from "@/mixins/chartRequestMixin";
  33. export default {
  34. name: "BoxPlotWithMedians",
  35. mixins: [myMixin],
  36. props: {
  37. fileAddr: {
  38. default: "",
  39. type: String,
  40. },
  41. index: {
  42. type: Number,
  43. },
  44. },
  45. data() {
  46. return {
  47. chartData: {},
  48. };
  49. },
  50. mounted() {
  51. this.getData();
  52. },
  53. methods: {
  54. async getData() {
  55. if (this.fileAddr !== "") {
  56. try {
  57. this.loading = true;
  58. this.cancelToken = axios.CancelToken.source();
  59. console.log(this.cancelToken);
  60. const resultChartsData = await axios.get(this.fileAddr, {
  61. cancelToken: this.cancelToken.token,
  62. });
  63. this.chartData = resultChartsData.data;
  64. this.drawBoxPlot();
  65. this.isError = false;
  66. this.loading = false;
  67. } catch (error) {
  68. this.isError = true;
  69. this.loading = false;
  70. }
  71. }
  72. },
  73. drawBoxPlot() {
  74. const chartContainer = this.$refs.plotlyChart;
  75. const { data, xaixs, yaixs, analysisTypeCode } = this.chartData;
  76. const traces = [];
  77. const medianMarkers = [];
  78. // 处理每组数据
  79. data.forEach((group) => {
  80. // 添加箱线图
  81. traces.push({
  82. x: group.xData,
  83. y: group.yData,
  84. type: "box",
  85. name: group.title,
  86. marker: {
  87. color: group.color,
  88. },
  89. boxmean: true, // 显示均值
  90. });
  91. // 添加中位点
  92. if (group.medians) {
  93. medianMarkers.push({
  94. x: group.medians.x,
  95. y: group.medians.y,
  96. mode: group.medians.mode,
  97. marker: {
  98. color: group.medians.color,
  99. size: group.medians.size,
  100. },
  101. name: `${group.title} - 中位点`,
  102. type: "scatter",
  103. });
  104. }
  105. });
  106. const layout = {
  107. title: analysisTypeCode + data[0].engineName,
  108. xaxis: {
  109. title: xaixs,
  110. },
  111. yaxis: {
  112. title: yaixs,
  113. },
  114. showlegend: true,
  115. };
  116. // 绘制图表
  117. Plotly.newPlot(chartContainer, [...traces, ...medianMarkers], layout);
  118. },
  119. },
  120. };
  121. </script>
  122. <style scoped>
  123. /* 可根据需要自定义样式 */
  124. </style>