|
|
@@ -76,7 +76,7 @@ export default {
|
|
|
chartType: "line", // 默认图表类型是折线图
|
|
|
color1: [], // 默认颜色
|
|
|
// 配色方案列表(每个方案是一个颜色数组)
|
|
|
- colorSchemes: [...colorSchemes],
|
|
|
+ colorSchemes: colorSchemes,
|
|
|
loading: false,
|
|
|
isError: false,
|
|
|
colors: [...colorSchemes[0].colors],
|
|
|
@@ -89,23 +89,29 @@ export default {
|
|
|
},
|
|
|
watch: {
|
|
|
themeColor: {
|
|
|
- handler() {
|
|
|
- this.color1 = this.themeColor;
|
|
|
- this.updateChartColor();
|
|
|
+ handler(newVal, oldVal) {
|
|
|
+ if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
|
|
|
+ this.color1 = newVal;
|
|
|
+ this.updateChartColor();
|
|
|
+ }
|
|
|
},
|
|
|
deep: true,
|
|
|
},
|
|
|
setUpImgData: {
|
|
|
- handler(newType) {
|
|
|
- this.drawChart();
|
|
|
+ handler(newVal, oldVal) {
|
|
|
+ if (JSON.stringify(newVal) !== JSON.stringify(oldVal)) {
|
|
|
+ this.drawChart();
|
|
|
+ }
|
|
|
},
|
|
|
deep: true,
|
|
|
},
|
|
|
},
|
|
|
mounted() {
|
|
|
if (this.fileAddr) {
|
|
|
- this.color1 = this.themeColor;
|
|
|
- this.getData();
|
|
|
+ this.$nextTick(() => {
|
|
|
+ this.color1 = this.colorSchemes[0].colors;
|
|
|
+ this.getData();
|
|
|
+ });
|
|
|
}
|
|
|
},
|
|
|
methods: {
|
|
|
@@ -123,9 +129,9 @@ export default {
|
|
|
// 使用 nextTick 来确保 DOM 渲染完成后绘制图表
|
|
|
nextTick(() => {
|
|
|
this.drawChart();
|
|
|
- this.isError = false;
|
|
|
- this.loading = false;
|
|
|
});
|
|
|
+ this.isError = false;
|
|
|
+ this.loading = false;
|
|
|
} catch (error) {
|
|
|
console.error("Error loading data:", error);
|
|
|
this.isError = true;
|
|
|
@@ -139,46 +145,54 @@ export default {
|
|
|
return false;
|
|
|
}
|
|
|
const data = [];
|
|
|
- this.chartData &&
|
|
|
- this.chartData.data &&
|
|
|
- this.chartData.data.forEach((turbine, index) => {
|
|
|
- // 判断图表类型,根据类型调整绘制方式
|
|
|
- const chartConfig = {
|
|
|
- x: turbine.xData, // X 数据
|
|
|
- y: turbine.yData, // Y 数据
|
|
|
- name: turbine.engineName, // 使用机组名称
|
|
|
- line: {
|
|
|
- color:
|
|
|
- this.color1.length > 0
|
|
|
- ? this.color1[index % this.color1.length]
|
|
|
- : this.colors[index % this.colors.length], // 为每个机组分配不同的颜色
|
|
|
- },
|
|
|
- marker: {
|
|
|
- color:
|
|
|
- this.color1.length > 0
|
|
|
- ? this.color1[index % this.color1.length]
|
|
|
- : this.colors[index % this.colors.length], // 为每个机组分配不同的颜色
|
|
|
- },
|
|
|
- hovertemplate:
|
|
|
- `${this.chartData.xaixs}:` +
|
|
|
- ` %{x} <br> ` +
|
|
|
- `${this.chartData.yaixs}:` +
|
|
|
- "%{y} <br>",
|
|
|
- };
|
|
|
- if (this.chartData.yaixs === "概率密度函数") {
|
|
|
- chartConfig.line.color = this.color1[12];
|
|
|
- }
|
|
|
- if (this.chartType === "line") {
|
|
|
- chartConfig.mode = "lines"; // 如果是折线图
|
|
|
- chartConfig.fill = "none";
|
|
|
- } else if (this.chartType === "bar") {
|
|
|
- // chartConfig.type = "bar"; // 如果是柱状图
|
|
|
- chartConfig.fill = "tonexty";
|
|
|
- }
|
|
|
+ const newData =
|
|
|
+ this.chartData.analysisTypeCode === "风电机组叶尖速比和风速分析"
|
|
|
+ ? this.chartData &&
|
|
|
+ this.chartData.data &&
|
|
|
+ JSON.parse(JSON.stringify(this.chartData.data)).sort((a, b) => {
|
|
|
+ return a.engineName.localeCompare(b.engineName);
|
|
|
+ })
|
|
|
+ : JSON.parse(JSON.stringify(this.chartData.data));
|
|
|
+ newData.forEach((turbine, index) => {
|
|
|
+ // 判断图表类型,根据类型调整绘制方式
|
|
|
+ const chartConfig = {
|
|
|
+ x: turbine.xData, // X 数据
|
|
|
+ y: turbine.yData, // Y 数据
|
|
|
+ name: turbine.engineName, // 使用机组名称
|
|
|
+ line: {
|
|
|
+ color:
|
|
|
+ this.color1.length > 0
|
|
|
+ ? this.color1[index % this.color1.length]
|
|
|
+ : this.colors[index % this.colors.length], // 为每个机组分配不同的颜色
|
|
|
+ },
|
|
|
+ marker: {
|
|
|
+ color:
|
|
|
+ this.color1.length > 0
|
|
|
+ ? this.color1[index % this.color1.length]
|
|
|
+ : this.colors[index % this.colors.length], // 为每个机组分配不同的颜色
|
|
|
+ },
|
|
|
+ hovertemplate:
|
|
|
+ `${this.chartData.xaixs}:` +
|
|
|
+ ` %{x} <br> ` +
|
|
|
+ `${this.chartData.yaixs}:` +
|
|
|
+ "%{y} <br>",
|
|
|
+ };
|
|
|
+ if (this.chartData.yaixs === "概率密度函数") {
|
|
|
+ console.log(this.color1[5], this.colors[5], "this.color1");
|
|
|
+ chartConfig.line.color =
|
|
|
+ this.color1.length > 0 ? this.color1[7] : this.colors[7]; // 为每个机组分配不同的颜色
|
|
|
+ }
|
|
|
+ if (this.chartType === "line") {
|
|
|
+ chartConfig.mode = "lines"; // 如果是折线图
|
|
|
+ chartConfig.fill = "none";
|
|
|
+ } else if (this.chartType === "bar") {
|
|
|
+ // chartConfig.type = "bar"; // 如果是柱状图
|
|
|
+ chartConfig.fill = "tonexty";
|
|
|
+ }
|
|
|
+
|
|
|
+ data.push(chartConfig);
|
|
|
+ });
|
|
|
|
|
|
- data.push(chartConfig);
|
|
|
- });
|
|
|
- console.log(this.chartData, "图表title");
|
|
|
const layout = {
|
|
|
title: {
|
|
|
text: this.chartData.title || this.chartData.data[0].title,
|
|
|
@@ -192,12 +206,28 @@ export default {
|
|
|
gridcolor: "rgb(255,255,255)",
|
|
|
tickcolor: "rgb(255,255,255)",
|
|
|
backgroundcolor: "#e5ecf6",
|
|
|
+ range:
|
|
|
+ this.chartData.analysisTypeCode === "风电机组风能利用系数分析" &&
|
|
|
+ this.chartData.contract_Cp_curve_xData
|
|
|
+ ? [
|
|
|
+ 0,
|
|
|
+ Math.max(
|
|
|
+ ...this.chartData.contract_Cp_curve_xData
|
|
|
+ .map(Number)
|
|
|
+ .filter((val) => !isNaN(val))
|
|
|
+ ) * 0.9,
|
|
|
+ ]
|
|
|
+ : undefined,
|
|
|
},
|
|
|
yaxis: {
|
|
|
title: this.chartData.yaixs || "Y轴", // 纵坐标标题
|
|
|
gridcolor: "rgb(255,255,255)",
|
|
|
tickcolor: "rgb(255,255,255)",
|
|
|
backgroundcolor: "#e5ecf6",
|
|
|
+ range:
|
|
|
+ this.chartData.analysisTypeCode === "风电机组风能利用系数分析"
|
|
|
+ ? [0, 1.5]
|
|
|
+ : undefined,
|
|
|
},
|
|
|
margin: {
|
|
|
l: 50,
|
|
|
@@ -271,6 +301,11 @@ export default {
|
|
|
};
|
|
|
},
|
|
|
},
|
|
|
+ beforeUnmount() {
|
|
|
+ if (this.cancelToken) {
|
|
|
+ this.cancelToken.cancel("组件卸载,取消请求");
|
|
|
+ }
|
|
|
+ },
|
|
|
};
|
|
|
</script>
|
|
|
|