|
@@ -1,22 +1,13 @@
|
|
|
-<!--
|
|
|
- * @Author: your name
|
|
|
- * @Date: 2024-09-11 14:29:26
|
|
|
- * @LastEditTime: 2025-01-13 15:12:38
|
|
|
- * @LastEditors: bogon
|
|
|
- * @Description: In User Settings Edit
|
|
|
- * @FilePath: /performance-test/src/views/performance/components/chartsCom/HeatmapCharts.vue
|
|
|
--->
|
|
|
<template>
|
|
|
<div>
|
|
|
- <!-- HeatmapCharts
|
|
|
- <h1>分钟级SCADA数据记录完整度分析</h1>
|
|
|
- <h1>秒级SCADA数据记录完整度分析</h1> -->
|
|
|
- <div :id="`chart-${inds}`" style="width: 100%; height: 550px"></div>
|
|
|
+ <div :id="`chart-${inds}`" style="width: 100%; height: 450px"></div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
+import { nextTick } from "vue"; // 导入 nextTick
|
|
|
import { allTypesDatas } from "@/utils/allTypesOfAnalysisData.js";
|
|
|
import Plotly from "plotly.js-dist";
|
|
|
+import axios from "axios";
|
|
|
export default {
|
|
|
props: {
|
|
|
inds: {
|
|
@@ -25,26 +16,103 @@ export default {
|
|
|
return 0;
|
|
|
},
|
|
|
},
|
|
|
+ fileAddr: {
|
|
|
+ type: String,
|
|
|
+ default: "",
|
|
|
+ },
|
|
|
},
|
|
|
data() {
|
|
|
return {
|
|
|
+ chartData: {},
|
|
|
initData: [
|
|
|
{
|
|
|
z: [
|
|
|
- [100, 95, 20, 7, 75, 100],
|
|
|
- [0, 50, 0, 0, 0, 0],
|
|
|
- [100, 74, 7, 95, 100, 100],
|
|
|
+ [
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5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 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ ],
|
|
|
+ [
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0, 5.0,
|
|
|
+ ],
|
|
|
],
|
|
|
x: [
|
|
|
- "#2024-01",
|
|
|
- "#2024-02",
|
|
|
- "#2024-03",
|
|
|
- "#2024-04",
|
|
|
- "#2024-05",
|
|
|
- "#2024-06",
|
|
|
+ "#01",
|
|
|
+ "#02",
|
|
|
+ "#03",
|
|
|
+ "#04",
|
|
|
+ "#05",
|
|
|
+ "#06",
|
|
|
+ "#07",
|
|
|
+ "#08",
|
|
|
+ "#09",
|
|
|
+ "#10",
|
|
|
+ "#11",
|
|
|
+ "#12",
|
|
|
+ "#13",
|
|
|
+ "#14",
|
|
|
+ "#15",
|
|
|
+ "#16",
|
|
|
+ "#17",
|
|
|
+ "#18",
|
|
|
+ "#19",
|
|
|
+ "#20",
|
|
|
+ "#21",
|
|
|
+ ],
|
|
|
+ y: [
|
|
|
+ "2023-01",
|
|
|
+ "2023-02",
|
|
|
+ "2023-03",
|
|
|
+ "2023-04",
|
|
|
+ "2023-05",
|
|
|
+ "2023-06",
|
|
|
+ "2023-07",
|
|
|
+ "2023-08",
|
|
|
+ "2023-09",
|
|
|
+ "2023-10",
|
|
|
+ "2023-11",
|
|
|
+ "2023-12",
|
|
|
],
|
|
|
- y: ["Morning", "Afternoon", "Evening"],
|
|
|
- // y: ["Morning", "Afternoon"],
|
|
|
type: "heatmap",
|
|
|
colorscale: "Viridis", //分钟scads
|
|
|
colorscale: [
|
|
@@ -62,63 +130,122 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
mounted() {
|
|
|
- this.initcharts();
|
|
|
+ this.getData();
|
|
|
+ if (this.fileAddr) {
|
|
|
+ this.getData();
|
|
|
+ }
|
|
|
},
|
|
|
+
|
|
|
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;
|
|
|
+ this.initData[0].y = resultChartsData.data[0].xData;
|
|
|
+ this.initData[0].z = resultChartsData.data[0].yData;
|
|
|
+ // 使用 nextTick 来确保 DOM 渲染完成后绘制图表
|
|
|
+ nextTick(() => {
|
|
|
+ this.initcharts();
|
|
|
+ // this.isError = false;
|
|
|
+ // this.loading = false;
|
|
|
+ });
|
|
|
+ } catch (error) {
|
|
|
+ console.error("Error loading data:", error);
|
|
|
+ this.isError = true;
|
|
|
+ this.loading = false;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ },
|
|
|
initcharts() {
|
|
|
const lineDatas = allTypesDatas.filter(
|
|
|
(item) =>
|
|
|
item.analysisTypeCode === "data_integrity_second" ||
|
|
|
item.analysisTypeCode === "data_integrity_minute"
|
|
|
)[0];
|
|
|
+
|
|
|
+ // 生成 annotations 数据
|
|
|
+
|
|
|
const layout = {
|
|
|
...lineDatas.lableConfig,
|
|
|
showlegend: false,
|
|
|
shapes: this.createShapesBorder(
|
|
|
this.initData[0].y.length,
|
|
|
- this.initData[0].x.length,
|
|
|
+ this.initData[0].x.length + 1,
|
|
|
1,
|
|
|
"white",
|
|
|
0
|
|
|
- ), // 添加边框
|
|
|
+ ),
|
|
|
+ // annotations: this.createAnnotations(this.initData[0].z),
|
|
|
margin: {
|
|
|
- l: 100, // 左侧边距,单位是像素
|
|
|
- r: 100, // 右侧边距,单位是像素
|
|
|
- t: 100, // 上方边距,单位是像素
|
|
|
- b: 100, // 下方边距,单位是像素
|
|
|
+ l: 100,
|
|
|
+ r: 100,
|
|
|
+ t: 100,
|
|
|
+ b: 100,
|
|
|
+ },
|
|
|
+ autosize: true,
|
|
|
+ yaxis: {
|
|
|
+ type: "category",
|
|
|
+ tickvals: this.initData[0].y, // 确保 Y 轴的值和你的数据匹配
|
|
|
+ ticktext: this.initData[0].y,
|
|
|
+ showticks: false,
|
|
|
+ showgrid: true,
|
|
|
+ },
|
|
|
+ xaxis: {
|
|
|
+ tickvals: this.initData[0].x,
|
|
|
+ ticktext: this.initData[0].x,
|
|
|
+ showticks: false,
|
|
|
+ showgrid: true,
|
|
|
},
|
|
|
- autosize: true, // 开启自适应
|
|
|
+ plot_bgcolor: "white", // 背景颜色设置为白色,确保背景和网格线一致
|
|
|
+ gridcolor: "#d3d3d3", // 设置网格线颜色
|
|
|
};
|
|
|
- // 添加注释
|
|
|
- for (var i = 0; i < this.initData[0].y.length; i++) {
|
|
|
- for (var j = 0; j < this.initData[0].x.length; j++) {
|
|
|
- const value = this.initData[0].z[i][j];
|
|
|
- const fontColor = value < 50 ? "#434443" : "white"; // 根据 z 值判断字体颜色
|
|
|
- var result = {
|
|
|
- xref: "x",
|
|
|
- yref: "y",
|
|
|
- x: this.initData[0].x[j],
|
|
|
- y: this.initData[0].y[i],
|
|
|
- text: this.initData[0].z[i][j],
|
|
|
- font: { size: 12, color: fontColor },
|
|
|
- showarrow: false,
|
|
|
- };
|
|
|
- layout.annotations.push(result);
|
|
|
- }
|
|
|
- }
|
|
|
Plotly.newPlot(`chart-${this.inds}`, this.initData, layout, {
|
|
|
responsive: true,
|
|
|
});
|
|
|
},
|
|
|
+ // createAnnotations(zData) {
|
|
|
+ // const annotations = [];
|
|
|
+ // for (let row = 0; row < zData.length; row++) {
|
|
|
+ // for (let col = 0; col < zData[row].length; col++) {
|
|
|
+ // const x = this.initData[0].x[col];
|
|
|
+ // const y = this.initData[0].y[row];
|
|
|
+ // const value = zData[row][col];
|
|
|
+
|
|
|
+ // // 打印 x, y, 和 value 检查是否为 NaN 或无效值
|
|
|
+ // console.log(`x: ${x}, y: ${y}, value: ${value}`);
|
|
|
+
|
|
|
+ // if (!isNaN(value)) {
|
|
|
+ // annotations.push({
|
|
|
+ // x: x,
|
|
|
+ // y: y,
|
|
|
+ // text: value.toString(),
|
|
|
+ // showarrow: false,
|
|
|
+ // font: {
|
|
|
+ // size: 10,
|
|
|
+ // color: "black",
|
|
|
+ // },
|
|
|
+ // align: "center",
|
|
|
+ // });
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // }
|
|
|
+ // return annotations;
|
|
|
+ // },
|
|
|
+
|
|
|
createShapesBorder(rows, cols, borderWidth, borderColor, offset) {
|
|
|
var shapes = [];
|
|
|
for (var row = 0; row < rows; row++) {
|
|
|
for (var col = 0; col < cols; col++) {
|
|
|
shapes.push({
|
|
|
type: "rect",
|
|
|
- x0: col - 0.5 - offset,
|
|
|
+ x0: col - 0.5 + offset,
|
|
|
x1: col + 0.5 + offset,
|
|
|
- y0: row - 0.5 - offset,
|
|
|
+ y0: row - 0.5 + offset,
|
|
|
y1: row + 0.5 + offset,
|
|
|
line: {
|
|
|
color: borderColor,
|