|
@@ -52,7 +52,7 @@
|
|
|
</template>
|
|
|
|
|
|
<script>
|
|
|
-import Plotly from "plotly.js-dist";
|
|
|
+import Plotly, { doCamera } from "plotly.js-dist";
|
|
|
import axios from "axios";
|
|
|
import { myMixin } from "@/mixins/chartRequestMixin";
|
|
|
import { colorSchemes } from "@/views/overview/js/colors";
|
|
@@ -105,8 +105,12 @@ export default {
|
|
|
},
|
|
|
watch: {
|
|
|
themeColor: {
|
|
|
- handler() {
|
|
|
- this.color1 = this.themeColor;
|
|
|
+ handler(newval) {
|
|
|
+ if (newval.length === 0) {
|
|
|
+ this.color1 = colorSchemes[0].colors;
|
|
|
+ } else {
|
|
|
+ this.color1 = newval;
|
|
|
+ }
|
|
|
this.updateChartColor();
|
|
|
},
|
|
|
deep: true,
|
|
@@ -120,7 +124,11 @@ export default {
|
|
|
},
|
|
|
async mounted() {
|
|
|
this.getData();
|
|
|
- this.color1 = this.themeColor;
|
|
|
+ if (this.themeColor.length === 0) {
|
|
|
+ this.color1 = colorSchemes[0].colors;
|
|
|
+ } else {
|
|
|
+ this.color1 = this.themeColor;
|
|
|
+ }
|
|
|
},
|
|
|
|
|
|
methods: {
|
|
@@ -154,7 +162,6 @@ export default {
|
|
|
}
|
|
|
}
|
|
|
},
|
|
|
-
|
|
|
// 格式化日期为 YY-MM 格式
|
|
|
formatDate(dateString) {
|
|
|
const date = new Date(dateString);
|
|
@@ -191,6 +198,14 @@ export default {
|
|
|
marker: {
|
|
|
size: this.pointSize,
|
|
|
color: monthColors[monthIndex],
|
|
|
+ opacity: 0.8,
|
|
|
+ lighting: {
|
|
|
+ ambient: 0.3, // 环境光(影响整体亮度)
|
|
|
+ diffuse: 1, // 漫反射光(增加真实感)
|
|
|
+ specular: 0.5, // 镜面反射(增强高光)
|
|
|
+ roughness: 0.5, // 低值=光滑表面,高值=粗糙表面
|
|
|
+ fresnel: 0.2, // 边缘高光强度
|
|
|
+ },
|
|
|
},
|
|
|
name: month, // 图例项名称,格式为 YY-MM
|
|
|
legendgroup: `month-${monthIndex}`, // 图例分组
|
|
@@ -216,91 +231,88 @@ export default {
|
|
|
},
|
|
|
scene: {
|
|
|
xaxis: {
|
|
|
- title: this.chartData.xaixs, // X 轴标题
|
|
|
- gridcolor: "rgb(255,255,255)",
|
|
|
- tickcolor: "rgb(255,255,255)",
|
|
|
- backgroundcolor: "#e5ecf6",
|
|
|
+ tickangle: 30,
|
|
|
+ title: {
|
|
|
+ text: this.chartData.xaixs,
|
|
|
+ standoff: 100, // 调整标题与轴线之间的间距(单位:像素)
|
|
|
+ }, // X 轴标题
|
|
|
+ gridcolor: "#fff",
|
|
|
+ backgroundcolor: "#rgba(0, 0, 0, 0.1)",
|
|
|
showbackground: true,
|
|
|
linewidth: 2, // 轴线宽度
|
|
|
linecolor: "black", // 轴线颜色
|
|
|
ticks: "outside", // 设置刻度线在轴线外
|
|
|
tickwidth: 2,
|
|
|
+ //刻度线长度
|
|
|
+ ticklen: 10,
|
|
|
tickcolor: "black",
|
|
|
+ zeroline: false, // 显示 X 轴的中轴线
|
|
|
},
|
|
|
yaxis: {
|
|
|
- title: this.chartData.yaixs, // Y 轴标题
|
|
|
+ title: {
|
|
|
+ text: this.chartData.yaixs,
|
|
|
+ standoff: 20,
|
|
|
+ },
|
|
|
tickformat: "%y-%m", // 设置 Y 轴的时间格式为 YY-MM
|
|
|
- gridcolor: "rgb(255,255,255)",
|
|
|
- tickcolor: "rgb(255,255,255)",
|
|
|
- backgroundcolor: "#e5ecf6",
|
|
|
+ gridcolor: "#fff",
|
|
|
+ tickcolor: "#e5ecf6",
|
|
|
+ // backgroundcolor: "#E6E6E6",
|
|
|
+ backgroundcolor: "#rgba(0, 0, 0, 0.1)",
|
|
|
showbackground: true,
|
|
|
linewidth: 2, // 轴线宽度
|
|
|
linecolor: "black", // 轴线颜色
|
|
|
ticks: "outside", // 设置刻度线在轴线外
|
|
|
tickwidth: 2,
|
|
|
tickcolor: "black",
|
|
|
+ ticklen: 10,
|
|
|
+ zeroline: false, // 显示 X 轴的中轴线
|
|
|
+ // tickangle: 70, // 设置Z轴刻度值的角度
|
|
|
},
|
|
|
zaxis: {
|
|
|
- title: this.chartData.zaixs, // Z 轴标题
|
|
|
- gridcolor: "rgb(255,255,255)",
|
|
|
- tickcolor: "rgb(255,255,255)",
|
|
|
- backgroundcolor: "#e5ecf6",
|
|
|
+ title: {
|
|
|
+ text: this.chartData.zaixs,
|
|
|
+ },
|
|
|
+ gridcolor: "#fff",
|
|
|
+ tickcolor: "#fff",
|
|
|
+ // backgroundcolor: "#E6E6E6",
|
|
|
+ backgroundcolor: "#rgba(0, 0, 0, 0.1)",
|
|
|
showbackground: true,
|
|
|
linewidth: 2, // 轴线宽度
|
|
|
linecolor: "black", // 轴线颜色
|
|
|
ticks: "outside", // 设置刻度线在轴线外
|
|
|
tickwidth: 2,
|
|
|
tickcolor: "black",
|
|
|
+ zeroline: false, // 显示 X 轴的中轴线
|
|
|
+ tickangle: 270, // 设置Z轴刻度值的角度
|
|
|
},
|
|
|
+ margin: { l: 300, r: 500, t: 100, b: 100 }, // ✅ 增加底部间距
|
|
|
+ // aspectmode: "cube", // 确保X/Y/Z轴比例固定,防止变形
|
|
|
bgcolor: "#e5ecf6", // 设置背景颜色
|
|
|
aspectratio: {
|
|
|
- x: 3,
|
|
|
- y: 1.5,
|
|
|
+ x: 2.2,
|
|
|
+ y: 1.8,
|
|
|
z: 1,
|
|
|
},
|
|
|
- plot_bgcolor: "#e5ecf6",
|
|
|
+ aspectmode: "manual", // ✅ 让 XYZ 轴比例不同
|
|
|
gridcolor: "#fff",
|
|
|
- backgroundcolor: "#e5ecf6", // 设置背景颜色为白色
|
|
|
- // camera: {
|
|
|
- // //原始3
|
|
|
- // center: {
|
|
|
- // x: -0.375472972541404,
|
|
|
- // y: -0.5585992748989729,
|
|
|
- // z: -0.02739771471583052,
|
|
|
- // },
|
|
|
- // eye: {
|
|
|
- // x: -0.5046744702181177,
|
|
|
- // y: -3.1376489494672195,
|
|
|
- // z: 1.7379514809127419,
|
|
|
- // },
|
|
|
- // up: {
|
|
|
- // x: 0.036764743754523974,
|
|
|
- // y: 0.5632076795906327,
|
|
|
- // z: 0.8254971007016315,
|
|
|
- // },
|
|
|
- // projection: {
|
|
|
- // type: "perspective",
|
|
|
- // },
|
|
|
- // },
|
|
|
- // aspectmode: "auto", // 让坐标轴自动适配
|
|
|
camera: {
|
|
|
up: {
|
|
|
- x: -0.0014269369124665849,
|
|
|
- y: 0.0012146694366401958,
|
|
|
- z: 0.9999982442130624,
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ z: 1,
|
|
|
},
|
|
|
center: {
|
|
|
- x: -0.4418147101642839,
|
|
|
- y: 0.11636199495350043,
|
|
|
- z: -0.4133154056555356,
|
|
|
+ x: 0,
|
|
|
+ y: 0,
|
|
|
+ z: 0,
|
|
|
},
|
|
|
eye: {
|
|
|
- x: -2.482948029595208,
|
|
|
- y: -2.2792871251589983,
|
|
|
- z: 1.0941053354561574,
|
|
|
+ x: -1.9411806339437676,
|
|
|
+ y: -1.0688695891896567,
|
|
|
+ z: 0.47888991188707036,
|
|
|
},
|
|
|
projection: {
|
|
|
- type: "perspective",
|
|
|
+ type: "orthographic",
|
|
|
},
|
|
|
},
|
|
|
},
|
|
@@ -313,6 +325,23 @@ export default {
|
|
|
},
|
|
|
},
|
|
|
};
|
|
|
+ const config = {
|
|
|
+ modeBarButtonsToAdd: [
|
|
|
+ {
|
|
|
+ name: "还原", // 自定义按钮
|
|
|
+ icon: Plotly.Icons.home,
|
|
|
+ click: () => this.resetCamera(),
|
|
|
+ },
|
|
|
+ ],
|
|
|
+ modeBarButtonsToRemove: [
|
|
|
+ "sendDataToCloud",
|
|
|
+ "autoScale2d",
|
|
|
+ "hoverClosest3d",
|
|
|
+ "resetCameraLastSave3d",
|
|
|
+ "resetCameraDefault3d",
|
|
|
+ ],
|
|
|
+ displaylogo: false, // 可选:隐藏 Plotly logo
|
|
|
+ };
|
|
|
// 获取x轴和y轴的设置
|
|
|
const getChartSetUp = (axisTitle) => {
|
|
|
return this.setUpImgData.find((item) => item.text.includes(axisTitle));
|
|
@@ -333,7 +362,7 @@ export default {
|
|
|
layout.scene.zaxis.dtick = zChartSetUp.dtick;
|
|
|
layout.scene.zaxis.range = [zChartSetUp.min, zChartSetUp.max];
|
|
|
}
|
|
|
- Plotly.newPlot(`plotly-3d-chart-` + this.index, traces, layout);
|
|
|
+ Plotly.newPlot(`plotly-3d-chart-` + this.index, traces, layout, config);
|
|
|
// 监听图表的 relayout 事件,获取并输出相机视角
|
|
|
const plotElement = document.getElementById(
|
|
|
`plotly-3d-chart-` + this.index
|
|
@@ -349,7 +378,36 @@ export default {
|
|
|
}
|
|
|
});
|
|
|
},
|
|
|
-
|
|
|
+ // 还原视角
|
|
|
+ resetCamera() {
|
|
|
+ Plotly.relayout(`plotly-3d-chart-` + this.index, {
|
|
|
+ "scene.camera": {
|
|
|
+ up: {
|
|
|
+ x: -0.0014269369124665849,
|
|
|
+ y: 0.0012146694366401958,
|
|
|
+ z: 0.9999982442130624,
|
|
|
+ },
|
|
|
+ center: {
|
|
|
+ x: -0.4418147101642839,
|
|
|
+ y: 0.11636199495350043,
|
|
|
+ z: -0.4133154056555356,
|
|
|
+ },
|
|
|
+ eye: {
|
|
|
+ x: -2.482948029595208,
|
|
|
+ y: -2.2792871251589983,
|
|
|
+ z: 1.0941053354561574,
|
|
|
+ },
|
|
|
+ projection: {
|
|
|
+ type: "perspective",
|
|
|
+ },
|
|
|
+ },
|
|
|
+ "scene.aspectratio": {
|
|
|
+ x: 3,
|
|
|
+ y: 1.5,
|
|
|
+ z: 1,
|
|
|
+ },
|
|
|
+ });
|
|
|
+ },
|
|
|
updateChartColor() {
|
|
|
this.renderChart(); // 当配色方案或点大小发生变化时重新渲染图表
|
|
|
},
|
|
@@ -374,7 +432,7 @@ export default {
|
|
|
/* 样式可以根据需求自定义 */
|
|
|
#plotly-3d-chart {
|
|
|
width: 100%;
|
|
|
- height: 500px;
|
|
|
+ height: 600px;
|
|
|
}
|
|
|
|
|
|
::v-deep canvas {
|