echarts修改

This commit is contained in:
978184212@qq.com 2025-12-08 18:24:48 +08:00
parent 171d257b5b
commit fdda6f0f6d
1 changed files with 165 additions and 156 deletions

View File

@ -150,7 +150,7 @@
resolt: [],
chartData: {},
opts: {
color: ["#1890FF", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272",
color: ["#c3c3c3","#1890FF", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272",
"#FC8452", "#9A60B4", "#ea7ccc"
],
padding: [0, 15, 10, 15],
@ -479,7 +479,7 @@
maskClick(e) {
this.rangetime = e;
},
//
// - getServerData
getServerData(val) {
const chartDataList = val.map(item => {
const series = [];
@ -495,33 +495,45 @@
series.push({
name: item.itemName,
data: mainData,
color: "#1890FF",
color: "#c3c3c3",
lineType: "solid",
pointShape: "circle",
show: true
});
// 线 - 线
// 线 - 线
if (highValNum !== null) {
series.push({
name: `最高阈值: ${highValNum}`,
data: Array(this.timeList?.length || 0).fill(highValNum),
color: "#FF4242",
lineType: "dashed", // 线
pointShape: "none", //
// 线
lineType: "dash", // "dashed", "dot", "dashdot"
dashLength: 10, // 线
gapLength: 5, //
pointShape: "none",
show: true,
// 使
custom: {
lineDash: [10, 5] // [线, ]
}
});
}
// 线 - 线
// 线
if (lowValNum !== null) {
series.push({
name: `最低阈值: ${lowValNum}`,
data: Array(this.timeList?.length || 0).fill(lowValNum),
color: "#19D58A",
lineType: "dashed", // 线
pointShape: "none", //
lineType: "dash",
dashLength: 10,
gapLength: 5,
pointShape: "none",
show: true,
custom: {
lineDash: [10, 5]
}
});
}
@ -532,7 +544,6 @@
};
});
// resolt
this.resolt = this.resolt.map((item, index) => {
return {
...item,
@ -541,13 +552,12 @@
chartOpts: chartDataList[index] ? chartDataList[index].chartOpts : this.getChartOpts(item.itemName, item.unit)
};
});
console.log("处理后的趋势图数据", this.resolt);
},
//
// getChartOpts线
getChartOpts(itemName, unit) {
return {
color: ["#1890FF", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272",
color: ["#c3c3c3", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272",
"#FC8452", "#9A60B4", "#ea7ccc"
],
padding: [0, 15, 10, 5],
@ -558,50 +568,21 @@
itemGap: 10,
margin: 10,
},
enableScroll: false, //
enableScroll: false,
dataLabel: false,
xAxis: {
disableGrid: true,
scrollShow: false, //
labelCount: 3, // 33
scrollShow: false,
labelCount: 3,
boundaryGap: 'justify',
//
labelFormatter: (val, i, allLabels) => {
if (!allLabels || allLabels.length === 0) {
return val;
}
if (!allLabels || allLabels.length === 0) return val;
const total = allLabels.length;
// 1.
if (i === 0) {
if (i === 0 || i === Math.floor(total / 2) || i === total - 3) {
return val;
}
// 2.
const middleIndex = Math.floor(total / 2);
if (total % 2 === 0 && i === middleIndex - 1) {
//
return val;
} else if (i === middleIndex) {
//
return val;
}
// 3.
//
if (total >= 3) {
const thirdLastIndex = total - 3;
if (i === thirdLastIndex) {
return val;
}
}
// 3
else if (i === total - 1) {
return val;
}
return ''; //
return '';
}
},
yAxis: {
@ -629,11 +610,39 @@
return `${category}\n${item.seriesName}: ${item.data}`
}
},
markLine: {
},
line: {
width: 2,
smooth: true
smooth: true,
// 线线
style: "dash", //
dashLength: 8, // 线
gapLength: 4, //
lineCap: "round" // 线
},
//
render: {
series: {
line: (canvas, config, series, index) => {
// 线
const ctx = canvas.getContext('2d');
ctx.save();
// 线12
if (index === 1 || index === 2) {
// 线
ctx.setLineDash([10, 5]); // 10px线5px
ctx.lineDashOffset = 0;
} else {
// 线
ctx.setLineDash([]);
}
//
config.chart.option.extra.render.series.line.call(this, canvas, config, series, index);
ctx.restore();
}
}
}
}
};