|
@@ -1,20 +1,3 @@
|
|
|
-<!--
|
|
|
- * @Author: your name
|
|
|
- * @Date: 2025-01-22 10:10:46
|
|
|
- * @LastEditTime: 2025-01-22 10:12:02
|
|
|
- * @LastEditors: bogon
|
|
|
- * @Description: In User Settings Edit
|
|
|
- * @FilePath: /performance-test/src/views/performance/components/chartsCom/YewErrorBarChart.vue
|
|
|
--->
|
|
|
-<!--
|
|
|
- * @Author: your name
|
|
|
- * @Date: 2024-09-11 14:30:17
|
|
|
- * @LastEditTime: 2025-01-20 17:31:39
|
|
|
- * @LastEditors: bogon
|
|
|
- * @Description: In User Settings Edit
|
|
|
- * @FilePath: /performance-test/src/views/performance/components/chartsCom/BarChart.vue
|
|
|
--->
|
|
|
-
|
|
|
<template>
|
|
|
<div>
|
|
|
<!-- 图表控制面板 -->
|
|
@@ -38,7 +21,7 @@
|
|
|
<!-- 图表容器 -->
|
|
|
<div
|
|
|
v-loading="loading"
|
|
|
- :id="`bar-chart${inds}`"
|
|
|
+ :id="`bar-chart-sum`"
|
|
|
style="width: 100%; height: 400px"
|
|
|
>
|
|
|
<el-empty v-if="isError" description="请求失败"></el-empty>
|
|
@@ -54,15 +37,9 @@ import { myMixin } from "@/mixins/chartRequestMixin";
|
|
|
|
|
|
export default {
|
|
|
props: {
|
|
|
- fileAddr: {
|
|
|
- default: "",
|
|
|
- type: String,
|
|
|
- },
|
|
|
- inds: {
|
|
|
- type: String,
|
|
|
- default() {
|
|
|
- return 0;
|
|
|
- },
|
|
|
+ zongFaultCsvData: {
|
|
|
+ default: [],
|
|
|
+ type: Array,
|
|
|
},
|
|
|
},
|
|
|
mixins: [myMixin],
|
|
@@ -74,18 +51,12 @@ export default {
|
|
|
engineTypeName: "",
|
|
|
xaixs: "",
|
|
|
yaixs: "",
|
|
|
- data: [
|
|
|
- // {
|
|
|
- // xData: ["2024-01-01", "2024-01-02", "2024-01-03", "2024-01-04", "2024-01-05"],
|
|
|
- // yData: [10, 20, 30, 40, 50],
|
|
|
- // title: "数据集1",
|
|
|
- // },
|
|
|
- ],
|
|
|
+ data: [],
|
|
|
},
|
|
|
chartType: "bar", // 当前图表类型 ('bar' 或 'scatter')
|
|
|
color1: "#406DAB", // 默认颜色
|
|
|
- // normalRangeMin: 5, // 最低范围
|
|
|
- // normalRangeMax: 18, // 最高范围
|
|
|
+ isError: false, // 错误标志
|
|
|
+ loading: true, // 加载标志
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
@@ -95,78 +66,72 @@ export default {
|
|
|
this.loading = false;
|
|
|
});
|
|
|
},
|
|
|
+
|
|
|
methods: {
|
|
|
- // async getData() {
|
|
|
- // if (this.fileAddr !== "") {
|
|
|
- // try {
|
|
|
- // this.loading = true;
|
|
|
- // this.cancelToken = axios.CancelToken.source();
|
|
|
- // const resultChartsData = await axios.get(this.fileAddr, {
|
|
|
- // cancelToken: this.cancelToken.token,
|
|
|
- // });
|
|
|
- // this.chartData = resultChartsData.data;
|
|
|
- // // 使用 nextTick 来确保 DOM 渲染完成后绘制图表
|
|
|
- // nextTick(() => {
|
|
|
- // this.drawChart();
|
|
|
- // this.isError = false;
|
|
|
- // this.loading = false;
|
|
|
- // });
|
|
|
- // } catch (error) {
|
|
|
- // console.error("Error loading data:", error);
|
|
|
- // this.isError = true;
|
|
|
- // this.loading = false;
|
|
|
- // }
|
|
|
- // }
|
|
|
- // },
|
|
|
- // 绘制图表
|
|
|
+ getData() {
|
|
|
+ console.log(this.zongFaultCsvData[0].data);
|
|
|
+ },
|
|
|
+ // 为每个数据点返回对应颜色
|
|
|
+ getColor(value) {
|
|
|
+ if (value <= 3) {
|
|
|
+ return "#8AC8BE"; // (0, 3]
|
|
|
+ } else if (value <= 5) {
|
|
|
+ return "#407DB3"; // (3, 5]
|
|
|
+ } else {
|
|
|
+ return "#1B2973"; // (5, ∞]
|
|
|
+ }
|
|
|
+ },
|
|
|
drawChart() {
|
|
|
- if (this.chartData.data.length === 0) return;
|
|
|
- const chartDataset = this.chartData.data[0];
|
|
|
+ const chartDataset = this.zongFaultCsvData[0].data;
|
|
|
+ const xData = chartDataset.map((item) => item.engine_name); // 机组编号
|
|
|
+ const yData = chartDataset.map((item) => item.yaw_error1); // 偏航误差值
|
|
|
+
|
|
|
+ // 为每个数据点分配颜色
|
|
|
+ const colors = yData.map(this.getColor);
|
|
|
+
|
|
|
const trace = {
|
|
|
- x: chartDataset.xData, // 横坐标数据
|
|
|
- y: chartDataset.yData, // 纵坐标数据
|
|
|
+ x: xData, // 横坐标数据
|
|
|
+ y: yData, // 纵坐标数据
|
|
|
type: this.chartType, // 当前图表类型 ('bar' 或 'scatter')
|
|
|
marker: {
|
|
|
- color: this.color1, // 柱状图颜色
|
|
|
+ color: colors, // 每个点的颜色
|
|
|
},
|
|
|
line: {
|
|
|
color: this.color1, // 折线图颜色
|
|
|
},
|
|
|
- name: chartDataset.title || "数据", // 图例名称
|
|
|
+ name: "偏航误差值", // 图例名称
|
|
|
};
|
|
|
|
|
|
- // Normal Range Lines
|
|
|
- const normalRangeLine = {
|
|
|
- x: chartDataset.xData, // 横坐标数据
|
|
|
- y: Array(chartDataset.xData.length).fill(this.normalRangeMin), // 最低值线
|
|
|
- mode: "lines",
|
|
|
- name: "LCL", // 图例名称(最低范围)
|
|
|
- line: {
|
|
|
- color: "red",
|
|
|
- width: 2,
|
|
|
- dash: "dash", // 虚线
|
|
|
- },
|
|
|
+ // 创建虚拟的 trace 以便显示图例
|
|
|
+ const legendTrace1 = {
|
|
|
+ x: [null],
|
|
|
+ y: [null],
|
|
|
+ name: "(0, 3]",
|
|
|
+ mode: "markers",
|
|
|
+ marker: { color: "#8AC8BE", size: 10 },
|
|
|
};
|
|
|
-
|
|
|
- const normalRangeMaxLine = {
|
|
|
- x: chartDataset.xData, // 横坐标数据
|
|
|
- y: Array(chartDataset.xData.length).fill(this.normalRangeMax), // 最高值线
|
|
|
- mode: "lines",
|
|
|
- name: "UCL", // 图例名称(最高范围)
|
|
|
- line: {
|
|
|
- color: "red",
|
|
|
- width: 2,
|
|
|
- dash: "dash", // 虚线
|
|
|
- },
|
|
|
+ const legendTrace2 = {
|
|
|
+ x: [null],
|
|
|
+ y: [null],
|
|
|
+ name: "(3, 5]",
|
|
|
+ mode: "markers",
|
|
|
+ marker: { color: "#407DB3", size: 10 },
|
|
|
+ };
|
|
|
+ const legendTrace3 = {
|
|
|
+ x: [null],
|
|
|
+ y: [null],
|
|
|
+ name: "(5, ∞]",
|
|
|
+ mode: "markers",
|
|
|
+ marker: { color: "#1B2973", size: 10 },
|
|
|
};
|
|
|
|
|
|
const layout = {
|
|
|
- title: this.chartData.analysisTypeCode || "图表", // 图表标题
|
|
|
+ title: "机组静态偏航误差值", // 图表标题
|
|
|
xaxis: {
|
|
|
- title: this.chartData.xaixs || "X轴", // 横坐标标题
|
|
|
+ title: "机组编号", // 横坐标标题
|
|
|
},
|
|
|
yaxis: {
|
|
|
- title: this.chartData.yaixs || "Y轴", // 纵坐标标题
|
|
|
+ title: "静态偏航误差值(度)", // 纵坐标标题
|
|
|
},
|
|
|
margin: {
|
|
|
l: 50,
|
|
@@ -175,14 +140,46 @@ export default {
|
|
|
b: 50,
|
|
|
},
|
|
|
autosize: true, // 开启自适应
|
|
|
+ showlegend: true, // 显示图例
|
|
|
+ legend: {
|
|
|
+ x: 1.05,
|
|
|
+ y: 1,
|
|
|
+ },
|
|
|
+ annotations: [
|
|
|
+ {
|
|
|
+ x: 1.05,
|
|
|
+ y: 4,
|
|
|
+ xref: "paper",
|
|
|
+ yref: "paper",
|
|
|
+ text: "(0, 3] ",
|
|
|
+ showarrow: false,
|
|
|
+ font: { size: 12, color: "#8AC8BE" },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ x: 1.05,
|
|
|
+ y: 3,
|
|
|
+ xref: "paper",
|
|
|
+ yref: "paper",
|
|
|
+ text: "(3, 5] ",
|
|
|
+ showarrow: false,
|
|
|
+ font: { size: 12, color: "#407DB3" },
|
|
|
+ },
|
|
|
+ {
|
|
|
+ x: 1.05,
|
|
|
+ y: 2,
|
|
|
+ xref: "paper",
|
|
|
+ yref: "paper",
|
|
|
+ text: "(5, ∞] ",
|
|
|
+ showarrow: false,
|
|
|
+ font: { size: 12, color: "#1B2973" },
|
|
|
+ },
|
|
|
+ ],
|
|
|
};
|
|
|
|
|
|
// 渲染图表
|
|
|
Plotly.newPlot(
|
|
|
- `bar-chart${this.inds}`,
|
|
|
-
|
|
|
- // [trace, normalRangeLine, normalRangeMaxLine],
|
|
|
- [trace],
|
|
|
+ `bar-chart-sum`,
|
|
|
+ [trace, legendTrace1, legendTrace2, legendTrace3],
|
|
|
layout,
|
|
|
{
|
|
|
responsive: true,
|