|
@@ -57,16 +57,27 @@ export default {
|
|
|
try {
|
|
|
this.loading = true;
|
|
|
this.cancelToken = axios.CancelToken.source();
|
|
|
- console.log(this.fileAddr, "3D url");
|
|
|
+
|
|
|
const resultChartsData = await axios.get(this.fileAddr, {
|
|
|
cancelToken: this.cancelToken.token,
|
|
|
});
|
|
|
- console.log(
|
|
|
- resultChartsData.data,
|
|
|
- JSON.parse(resultChartsData.data),
|
|
|
- "解析3D数据"
|
|
|
- );
|
|
|
- this.chartData = resultChartsData.data;
|
|
|
+ console.log(this.fileAddr, "解析3D数据");
|
|
|
+ if (typeof resultChartsData.data === "string") {
|
|
|
+ let dataString = resultChartsData.data;
|
|
|
+ // 如果数据字符串的开头和结尾可能有多余的字符(比如非法字符),可以进行清理
|
|
|
+ dataString = dataString.trim(); // 去除前后空格
|
|
|
+ // 如果数据包含了类似 "Infinity" 或其他无法解析的字符,替换它们
|
|
|
+ dataString = dataString.replace(/Infinity/g, '"Infinity"'); // 例如,将 "Infinity" 转换为字符串
|
|
|
+ try {
|
|
|
+ const parsedData = JSON.parse(dataString);
|
|
|
+ this.chartData = parsedData;
|
|
|
+ } catch (error) {
|
|
|
+ console.error("JSON 解析失败:", error);
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ this.chartData = resultChartsData.data;
|
|
|
+ }
|
|
|
+ // this.chartData = resultChartsData.data;
|
|
|
this.renderChart();
|
|
|
this.isError = false;
|
|
|
this.loading = false;
|
|
@@ -76,9 +87,106 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
+ // renderChart() {
|
|
|
+ // // 构造3D散点图数据
|
|
|
+
|
|
|
+ // const trace = {
|
|
|
+ // x: this.chartData.data[0].xData, // 发电机转速
|
|
|
+ // y: this.chartData.data[0].yData, // 时间
|
|
|
+ // z: this.chartData.data[0].zData, // 有功功率
|
|
|
+ // mode: "markers", // 强制设置为markers,避免出现线条
|
|
|
+ // type: "scatter3d", // 3D 散点图
|
|
|
+ // marker: {
|
|
|
+ // size: 2, // 点的大小
|
|
|
+ // color: this.chartData.data[0].zData, // 根据 Z 数据设置颜色
|
|
|
+ // colorscale: this.color1
|
|
|
+ // ? [
|
|
|
+ // [0, "#F9FDD2"], // 颜色从 this.color1 开始
|
|
|
+ // [1, this.color1], // 结束颜色为其他颜色
|
|
|
+ // ]
|
|
|
+ // : [
|
|
|
+ // [0, "#F9FDD2"],
|
|
|
+ // [0.15, "#E9F6BD"],
|
|
|
+ // [0.3, "#C2E3B9"],
|
|
|
+ // [0.45, "#8AC8BE"],
|
|
|
+ // [0.6, "#5CA8BF"],
|
|
|
+ // [0.75, "#407DB3"],
|
|
|
+ // [0.9, "#2E4C9A"],
|
|
|
+ // [1, "#1B2973"],
|
|
|
+ // ],
|
|
|
+ // },
|
|
|
+ // name: this.chartData.data[0].color, // 图例显示的名称,使用 color 数据
|
|
|
+ // legendgroup: this.chartData.data[0].color, // 使用 color 数据作为图例组
|
|
|
+ // };
|
|
|
+ // const config = { scrollZoom: true };
|
|
|
+
|
|
|
+ // const layout = {
|
|
|
+ // title: this.chartData.data[0].title,
|
|
|
+ // scene: {
|
|
|
+ // xaxis: {
|
|
|
+ // title: this.chartData.xaixs, // X 轴标题
|
|
|
+ // gridcolor: "rgb(255,255,255)", // 网格线颜色
|
|
|
+ // tickcolor: "rgb(255,255,255)",
|
|
|
+ // backgroundcolor: "#e5ecf6",
|
|
|
+ // showbackground: true, // 显示背景
|
|
|
+ // },
|
|
|
+ // yaxis: {
|
|
|
+ // title: this.chartData.yaixs, // Y 轴标题
|
|
|
+ // gridcolor: "rgb(255,255,255)", // 网格线颜色
|
|
|
+ // tickcolor: "rgb(255,255,255)",
|
|
|
+ // backgroundcolor: "#e5ecf6",
|
|
|
+ // showbackground: true, // 显示背景
|
|
|
+ // },
|
|
|
+ // zaxis: {
|
|
|
+ // title: this.chartData.zaixs, // Z 轴标题
|
|
|
+ // gridcolor: "rgb(255,255,255)", // 网格线颜色
|
|
|
+ // tickcolor: "rgb(255,255,255)",
|
|
|
+ // backgroundcolor: "#e5ecf6",
|
|
|
+ // showbackground: true, // 显示背景
|
|
|
+ // },
|
|
|
+ // aspectratio: {
|
|
|
+ // x: 1, // X 轴比例
|
|
|
+ // y: 3, // Y 轴比例
|
|
|
+ // z: 1, // Z 轴比例(可根据需要调整)
|
|
|
+ // },
|
|
|
+ // plot_bgcolor: "#e5ecf6",
|
|
|
+ // gridcolor: "#fff", // 设置网格线颜色
|
|
|
+ // camera: {
|
|
|
+ // center: {
|
|
|
+ // x: 0, // 设置中心点
|
|
|
+ // y: 0, // 设置中心点
|
|
|
+ // z: 0, // 设置中心点
|
|
|
+ // },
|
|
|
+ // eye: {
|
|
|
+ // x: 0, // 眼睛的位置
|
|
|
+ // y: 0, // 眼睛的位置
|
|
|
+ // z: 2.5, // 眼睛的位置
|
|
|
+ // },
|
|
|
+ // up: {
|
|
|
+ // x: 0, // 设置上方向
|
|
|
+ // y: 0, // 设置上方向
|
|
|
+ // z: 1, // 设置上方向
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // },
|
|
|
+ // margin: { t: 50, b: 50, l: 50, r: 50 }, // 图表边距
|
|
|
+ // staticPlot: false,
|
|
|
+ // legend: {
|
|
|
+ // x: 0.8, // 图例的 X 位置
|
|
|
+ // y: 0.9, // 图例的 Y 位置
|
|
|
+ // title: {
|
|
|
+ // text: this.chartData.yaixs, // 图例标题
|
|
|
+ // },
|
|
|
+ // bgcolor: "rgba(255, 255, 255, 0.7)", // 图例背景色
|
|
|
+ // bordercolor: "black", // 图例边框颜色
|
|
|
+ // borderwidth: 1, // 图例边框宽度
|
|
|
+ // },
|
|
|
+ // };
|
|
|
+ // console.log(trace, "渲染图表3Ds");
|
|
|
+ // Plotly.newPlot(`plotly-3d-chart-` + this.index, [trace], layout, config);
|
|
|
+ // },
|
|
|
renderChart() {
|
|
|
// 构造3D散点图数据
|
|
|
-
|
|
|
const trace = {
|
|
|
x: this.chartData.data[0].xData, // 发电机转速
|
|
|
y: this.chartData.data[0].yData, // 时间
|
|
@@ -87,7 +195,7 @@ export default {
|
|
|
type: "scatter3d", // 3D 散点图
|
|
|
marker: {
|
|
|
size: 2, // 点的大小
|
|
|
- color: this.chartData.data[0].zData, // 根据 Z 数据设置颜色
|
|
|
+ color: this.chartData.data[0].zData, // 这里的 zData 用于决定每个点的颜色
|
|
|
colorscale: this.color1
|
|
|
? [
|
|
|
[0, "#F9FDD2"], // 颜色从 this.color1 开始
|
|
@@ -102,9 +210,27 @@ export default {
|
|
|
[0.75, "#407DB3"],
|
|
|
[0.9, "#2E4C9A"],
|
|
|
[1, "#1B2973"],
|
|
|
- ],
|
|
|
+ ], // 自定义颜色渐变
|
|
|
+ colorbar: {
|
|
|
+ title: this.chartData.yaixs, // 色带标题
|
|
|
+ // tickvals: [0, 0.5, 1], // 设置色带刻度值
|
|
|
+ // ticktext: ["低", "中", "高"], // 设置刻度文本
|
|
|
+ // tickmode: "array", // 使用数组模式
|
|
|
+ ticks: "outside", // 设置刻度显示方向
|
|
|
+ tickangle: 45, // 设置刻度文字角度
|
|
|
+ },
|
|
|
},
|
|
|
+ name: "数据系列", // 图例名称
|
|
|
+ // legendgroup: "group1", // 图例组
|
|
|
+ hovertemplate:
|
|
|
+ `${this.chartData.xaixs}:` +
|
|
|
+ ` %{x} <br> ` +
|
|
|
+ `${this.chartData.yaixs}:` +
|
|
|
+ "%{y} <br>" +
|
|
|
+ `${this.chartData.zaixs}:` +
|
|
|
+ "%{z} <br>",
|
|
|
};
|
|
|
+
|
|
|
const config = { scrollZoom: true };
|
|
|
|
|
|
const layout = {
|
|
@@ -134,7 +260,7 @@ export default {
|
|
|
aspectratio: {
|
|
|
x: 1, // X 轴比例
|
|
|
y: 3, // Y 轴比例
|
|
|
- z: 1, // Z 轴比例(可根据需要调整)
|
|
|
+ z: 1, // Z 轴比例
|
|
|
},
|
|
|
plot_bgcolor: "#e5ecf6",
|
|
|
gridcolor: "#fff", // 设置网格线颜色
|
|
@@ -159,7 +285,7 @@ export default {
|
|
|
margin: { t: 50, b: 50, l: 50, r: 50 }, // 图表边距
|
|
|
staticPlot: false,
|
|
|
};
|
|
|
- console.log(trace, "渲染图表3Ds");
|
|
|
+
|
|
|
Plotly.newPlot(`plotly-3d-chart-` + this.index, [trace], layout, config);
|
|
|
},
|
|
|
},
|