|
@@ -1,34 +1,63 @@
|
|
|
<template>
|
|
|
- <div style="height: 600px">
|
|
|
- <div
|
|
|
- :id="`plotly-3d-chart-` + index"
|
|
|
- style="width: 100%; height: 600px"
|
|
|
- ></div>
|
|
|
- <div
|
|
|
- v-loading="loading"
|
|
|
- :id="`plotly-3d-chart-` + index"
|
|
|
- ref="plotlyChart"
|
|
|
- style="height: 600px"
|
|
|
- >
|
|
|
- <el-empty v-if="isError" description="请求失败"></el-empty>
|
|
|
+ <div>
|
|
|
+ <!-- 配色方案选择和图表类型切换 -->
|
|
|
+ <div style="display: flex; align-items: center; padding-top: 20px">
|
|
|
+ <div style="margin-right: 20px; display: flex; align-items: center">
|
|
|
+ <el-select
|
|
|
+ size="small"
|
|
|
+ v-model="color1"
|
|
|
+ @change="updateChartColor"
|
|
|
+ placeholder="选择配色方案"
|
|
|
+ style="width: 200px"
|
|
|
+ >
|
|
|
+ <el-option
|
|
|
+ v-for="(scheme, index) in colorSchemes"
|
|
|
+ :key="index"
|
|
|
+ :label="scheme.label"
|
|
|
+ :value="scheme.colors"
|
|
|
+ :style="getOptionStyle(scheme.colors)"
|
|
|
+ ></el-option>
|
|
|
+ </el-select>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div>
|
|
|
- <!-- <div>
|
|
|
- <div
|
|
|
- v-loading="loading"
|
|
|
- :id="`plotly-3d-chart-` + index"
|
|
|
- ref="plotlyChart"
|
|
|
- style="height: 600px"
|
|
|
- >
|
|
|
- <el-empty v-if="isError" description="请求失败"></el-empty>
|
|
|
+ <!-- 点大小控制 -->
|
|
|
+ <div style="display: flex; align-items: center">
|
|
|
+ <el-slider
|
|
|
+ v-model="pointSize"
|
|
|
+ :min="1"
|
|
|
+ :max="15"
|
|
|
+ :step="1"
|
|
|
+ label="点的大小"
|
|
|
+ show-stops
|
|
|
+ style="width: 150px"
|
|
|
+ @change="updateChartColor"
|
|
|
+ ></el-slider>
|
|
|
+ </div>
|
|
|
+
|
|
|
+ <!-- 图表展示区域 -->
|
|
|
+ <div style="height: 600px">
|
|
|
+ <div
|
|
|
+ :id="`plotly-3d-chart-` + index"
|
|
|
+ style="width: 100%; height: 600px"
|
|
|
+ ></div>
|
|
|
+ <div
|
|
|
+ v-loading="loading"
|
|
|
+ :id="`plotly-3d-chart-` + index"
|
|
|
+ ref="plotlyChart"
|
|
|
+ style="height: 600px"
|
|
|
+ >
|
|
|
+ <el-empty v-if="isError" description="请求失败"></el-empty>
|
|
|
+ </div>
|
|
|
</div>
|
|
|
- </div> -->
|
|
|
+ </div>
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
import Plotly from "plotly.js-dist";
|
|
|
import axios from "axios";
|
|
|
import { myMixin } from "@/mixins/chartRequestMixin";
|
|
|
+import { colorSchemes } from "@/views/overview/js/colors";
|
|
|
+
|
|
|
export default {
|
|
|
props: {
|
|
|
fileAddr: {
|
|
@@ -42,8 +71,27 @@ export default {
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
- color1: "",
|
|
|
+ color1: [
|
|
|
+ "#DBEEBC",
|
|
|
+ "#A8D7BE",
|
|
|
+ "#8ECAC1",
|
|
|
+ "#77BDC2",
|
|
|
+ "#64ADC2",
|
|
|
+ "#559ABE",
|
|
|
+ "#4884B7",
|
|
|
+ "#406DAB",
|
|
|
+ "#3856A0",
|
|
|
+ "#314291",
|
|
|
+ "#28357A",
|
|
|
+ "#1A285E",
|
|
|
+ "#FF7F50",
|
|
|
+ "#FFD700",
|
|
|
+ "#90EE90",
|
|
|
+ ], // 默认颜色
|
|
|
chartData: {},
|
|
|
+ chartType: "scatter", // 当前图表类型(默认是散点图)
|
|
|
+ colorSchemes: [...colorSchemes],
|
|
|
+ pointSize: 2, // 默认点大小
|
|
|
};
|
|
|
},
|
|
|
mixins: [myMixin],
|
|
@@ -61,13 +109,10 @@ export default {
|
|
|
const resultChartsData = await axios.get(this.fileAddr, {
|
|
|
cancelToken: this.cancelToken.token,
|
|
|
});
|
|
|
- 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" 转换为字符串
|
|
|
+ dataString = dataString.replace(/Infinity/g, '"Infinity"'); // 替换 Infinity 为 "Infinity"
|
|
|
try {
|
|
|
const parsedData = JSON.parse(dataString);
|
|
|
this.chartData = parsedData;
|
|
@@ -77,7 +122,6 @@ export default {
|
|
|
} else {
|
|
|
this.chartData = resultChartsData.data;
|
|
|
}
|
|
|
- // this.chartData = resultChartsData.data;
|
|
|
this.renderChart();
|
|
|
this.isError = false;
|
|
|
this.loading = false;
|
|
@@ -87,206 +131,111 @@ 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 };
|
|
|
+ // 更新配色方案
|
|
|
+ updateChartColor() {
|
|
|
+ this.renderChart(); // 当配色方案或点大小发生变化时重新渲染图表
|
|
|
+ },
|
|
|
|
|
|
- // 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, // 时间
|
|
|
- z: this.chartData.data[0].zData, // 有功功率
|
|
|
- mode: "markers", // 强制设置为markers,避免出现线条
|
|
|
- type: "scatter3d", // 3D 散点图
|
|
|
- marker: {
|
|
|
- size: 2, // 点的大小
|
|
|
- color: this.chartData.data[0].zData, // 这里的 zData 用于决定每个点的颜色
|
|
|
- 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"],
|
|
|
- ], // 自定义颜色渐变
|
|
|
- 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>",
|
|
|
+ // 切换图表类型
|
|
|
+ setChartType(type) {
|
|
|
+ this.chartType = type;
|
|
|
+ this.renderChart(); // 切换图表类型时重新渲染图表
|
|
|
+ },
|
|
|
+
|
|
|
+ // 获取配色选项样式
|
|
|
+ getOptionStyle(scheme) {
|
|
|
+ return {
|
|
|
+ background: `linear-gradient(to right, ${scheme.join(", ")})`,
|
|
|
+ color: "#fff",
|
|
|
+ height: "30px",
|
|
|
+ lineHeight: "30px",
|
|
|
+ borderRadius: "4px",
|
|
|
};
|
|
|
+ },
|
|
|
+
|
|
|
+ renderChart() {
|
|
|
+ const uniqueColors = [...new Set(this.chartData.data[0].color)];
|
|
|
+ if (!this.color1) {
|
|
|
+ this.color1 = colorSchemes[0].colors;
|
|
|
+ }
|
|
|
+ const traces = uniqueColors.map((color, idx) => {
|
|
|
+ const colorData = this.chartData.data[0].color.map((c) =>
|
|
|
+ c === color ? 1 : 0
|
|
|
+ );
|
|
|
|
|
|
- const config = { scrollZoom: true };
|
|
|
+ const trace = {
|
|
|
+ x: this.chartData.data[0].xData.filter((_, i) => colorData[i] === 1),
|
|
|
+ y: this.chartData.data[0].yData.filter((_, i) => colorData[i] === 1),
|
|
|
+ z: this.chartData.data[0].zData.filter((_, i) => colorData[i] === 1),
|
|
|
+ mode: this.chartType === "scatter" ? "markers" : "lines", // 根据选择的图表类型来设置模式
|
|
|
+ type: "scatter3d",
|
|
|
+ marker: {
|
|
|
+ size: this.pointSize, // 使用动态点大小
|
|
|
+ color: this.color1[idx], // 使用配色方案
|
|
|
+ colorscale: "YlGnBu",
|
|
|
+ },
|
|
|
+ name: ` ${color}`,
|
|
|
+ legendgroup: `group-${idx}`,
|
|
|
+ hovertemplate:
|
|
|
+ `${this.chartData.xaixs}:` +
|
|
|
+ ` %{x} <br> ` +
|
|
|
+ `${this.chartData.yaixs}:` +
|
|
|
+ "%{y} <br>" +
|
|
|
+ `${this.chartData.zaixs}:` +
|
|
|
+ "%{z} <br>",
|
|
|
+ };
|
|
|
+ return trace;
|
|
|
+ });
|
|
|
|
|
|
const layout = {
|
|
|
title: this.chartData.data[0].title,
|
|
|
scene: {
|
|
|
xaxis: {
|
|
|
- title: this.chartData.xaixs, // X 轴标题
|
|
|
- gridcolor: "rgb(255,255,255)", // 网格线颜色
|
|
|
+ title: this.chartData.xaixs,
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
tickcolor: "rgb(255,255,255)",
|
|
|
backgroundcolor: "#e5ecf6",
|
|
|
- showbackground: true, // 显示背景
|
|
|
+ showbackground: true,
|
|
|
},
|
|
|
yaxis: {
|
|
|
- title: this.chartData.yaixs, // Y 轴标题
|
|
|
- gridcolor: "rgb(255,255,255)", // 网格线颜色
|
|
|
+ title: this.chartData.yaixs,
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
tickcolor: "rgb(255,255,255)",
|
|
|
backgroundcolor: "#e5ecf6",
|
|
|
- showbackground: true, // 显示背景
|
|
|
+ showbackground: true,
|
|
|
},
|
|
|
zaxis: {
|
|
|
- title: this.chartData.zaixs, // Z 轴标题
|
|
|
- gridcolor: "rgb(255,255,255)", // 网格线颜色
|
|
|
+ title: this.chartData.zaixs,
|
|
|
+ gridcolor: "rgb(255,255,255)",
|
|
|
tickcolor: "rgb(255,255,255)",
|
|
|
backgroundcolor: "#e5ecf6",
|
|
|
- showbackground: true, // 显示背景
|
|
|
- },
|
|
|
- aspectratio: {
|
|
|
- x: 1, // X 轴比例
|
|
|
- y: 3, // Y 轴比例
|
|
|
- z: 1, // Z 轴比例
|
|
|
+ showbackground: true,
|
|
|
},
|
|
|
+ // aspectratio: {
|
|
|
+ // x: 1,
|
|
|
+ // y: 3,
|
|
|
+ // z: 1,
|
|
|
+ // },
|
|
|
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, // 设置上方向
|
|
|
- },
|
|
|
- },
|
|
|
+ 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 }, // 图表边距
|
|
|
+ margin: { t: 50, b: 50, l: 50, r: 50 },
|
|
|
staticPlot: false,
|
|
|
+ showlegend: true,
|
|
|
+ legend: {
|
|
|
+ marker: {
|
|
|
+ size: 10, // 图例中点的大小
|
|
|
+ },
|
|
|
+ },
|
|
|
};
|
|
|
|
|
|
- Plotly.newPlot(`plotly-3d-chart-` + this.index, [trace], layout, config);
|
|
|
+ Plotly.newPlot(`plotly-3d-chart-` + this.index, traces, layout);
|
|
|
},
|
|
|
},
|
|
|
};
|