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: [], resolt: [],
chartData: {}, chartData: {},
opts: { opts: {
color: ["#1890FF", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", color: ["#c3c3c3","#1890FF", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272",
"#FC8452", "#9A60B4", "#ea7ccc" "#FC8452", "#9A60B4", "#ea7ccc"
], ],
padding: [0, 15, 10, 15], padding: [0, 15, 10, 15],
@ -479,164 +479,173 @@
maskClick(e) { maskClick(e) {
this.rangetime = e; this.rangetime = e;
}, },
// // - getServerData
getServerData(val) { getServerData(val) {
const chartDataList = val.map(item => { const chartDataList = val.map(item => {
const series = []; const series = [];
// //
const mainData = (item.data.slice(0, 50) || Array(this.timeList?.length || 0).fill(0)) const mainData = (item.data.slice(0, 50) || Array(this.timeList?.length || 0).fill(0))
.map(value => Number(value) || 0); .map(value => Number(value) || 0);
const highValNum = item.highVal ? Number(item.highVal) || 0 : null; const highValNum = item.highVal ? Number(item.highVal) || 0 : null;
const lowValNum = item.lowVal ? Number(item.lowVal) || 0 : null; const lowValNum = item.lowVal ? Number(item.lowVal) || 0 : null;
// 线 - 线 // 线 - 线
series.push({ series.push({
name: item.itemName, name: item.itemName,
data: mainData, data: mainData,
color: "#1890FF", color: "#c3c3c3",
lineType: "solid", lineType: "solid",
pointShape: "circle", pointShape: "circle",
show: true show: true
}); });
// 线 - 线 // 线 - 线
if (highValNum !== null) { if (highValNum !== null) {
series.push({ series.push({
name: `最高阈值: ${highValNum}`, name: `最高阈值: ${highValNum}`,
data: Array(this.timeList?.length || 0).fill(highValNum), data: Array(this.timeList?.length || 0).fill(highValNum),
color: "#FF4242", color: "#FF4242",
lineType: "dashed", // 线 // 线
pointShape: "none", // lineType: "dash", // "dashed", "dot", "dashdot"
show: true, dashLength: 10, // 线
}); gapLength: 5, //
} pointShape: "none",
show: true,
// 线 - 线 // 使
if (lowValNum !== null) { custom: {
series.push({ lineDash: [10, 5] // [线, ]
name: `最低阈值: ${lowValNum}`, }
data: Array(this.timeList?.length || 0).fill(lowValNum), });
color: "#19D58A", }
lineType: "dashed", // 线
pointShape: "none", // // 线
show: true, if (lowValNum !== null) {
}); series.push({
} name: `最低阈值: ${lowValNum}`,
data: Array(this.timeList?.length || 0).fill(lowValNum),
return { color: "#19D58A",
categories: this.timeList.slice(0, 50) || [], lineType: "dash",
series: series, dashLength: 10,
chartOpts: this.getChartOpts(item.itemName, item.unit) gapLength: 5,
}; pointShape: "none",
}); show: true,
custom: {
// resolt lineDash: [10, 5]
this.resolt = this.resolt.map((item, index) => { }
return { });
...item, }
chartData: chartDataList[index] ? chartDataList[index].series : [],
categories: chartDataList[index] ? chartDataList[index].categories : [], return {
chartOpts: chartDataList[index] ? chartDataList[index].chartOpts : this.getChartOpts(item.itemName, item.unit) categories: this.timeList.slice(0, 50) || [],
}; series: series,
}); chartOpts: this.getChartOpts(item.itemName, item.unit)
console.log("处理后的趋势图数据", this.resolt); };
});
this.resolt = this.resolt.map((item, index) => {
return {
...item,
chartData: chartDataList[index] ? chartDataList[index].series : [],
categories: chartDataList[index] ? chartDataList[index].categories : [],
chartOpts: chartDataList[index] ? chartDataList[index].chartOpts : this.getChartOpts(item.itemName, item.unit)
};
});
}, },
// // getChartOpts线
getChartOpts(itemName, unit) { getChartOpts(itemName, unit) {
return { return {
color: ["#1890FF", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272", color: ["#c3c3c3", "#FF4242", "#19D58A", "#91CB74", "#FAC858", "#EE6666", "#73C0DE", "#3CA272",
"#FC8452", "#9A60B4", "#ea7ccc" "#FC8452", "#9A60B4", "#ea7ccc"
], ],
padding: [0, 15, 10, 5], padding: [0, 15, 10, 5],
legend: { legend: {
show: true, show: true,
position: "top", position: "top",
float: "right", float: "right",
itemGap: 10, itemGap: 10,
margin: 10, margin: 10,
}, },
enableScroll: false, // enableScroll: false,
dataLabel: false, dataLabel: false,
xAxis: { xAxis: {
disableGrid: true, disableGrid: true,
scrollShow: false, // scrollShow: false,
labelCount: 3, // 33 labelCount: 3,
boundaryGap: 'justify', boundaryGap: 'justify',
// labelFormatter: (val, i, allLabels) => {
labelFormatter: (val, i, allLabels) => { if (!allLabels || allLabels.length === 0) return val;
if (!allLabels || allLabels.length === 0) {
return val; const total = allLabels.length;
} if (i === 0 || i === Math.floor(total / 2) || i === total - 3) {
return val;
const total = allLabels.length; }
return '';
// 1. }
if (i === 0) { },
return val; yAxis: {
} gridType: "dash",
dashLength: 2,
// 2. showTitle: true,
const middleIndex = Math.floor(total / 2); data: [{
if (total % 2 === 0 && i === middleIndex - 1) { title: unit || '单位',
// }],
return val; },
} else if (i === middleIndex) { extra: {
// area: {
return val; type: "curve",
} opacity: 0.2,
addLine: true,
// 3. width: 2,
// gradient: true,
if (total >= 3) { activeType: "hollow"
const thirdLastIndex = total - 3; },
if (i === thirdLastIndex) { tooltip: {
return val; textStyle: {
} fontSize: 12
} },
// 3 format: (item, category, index, opts) => {
else if (i === total - 1) { return `${category}\n${item.seriesName}: ${item.data}`
return val; }
} },
line: {
return ''; // width: 2,
} smooth: true,
}, // 线线
yAxis: { style: "dash", //
gridType: "dash", dashLength: 8, // 线
dashLength: 2, gapLength: 4, //
showTitle: true, lineCap: "round" // 线
data: [{ },
title: unit || '单位', //
}], render: {
}, series: {
extra: { line: (canvas, config, series, index) => {
area: { // 线
type: "curve", const ctx = canvas.getContext('2d');
opacity: 0.2, ctx.save();
addLine: true,
width: 2, // 线12
gradient: true, if (index === 1 || index === 2) {
activeType: "hollow" // 线
}, ctx.setLineDash([10, 5]); // 10px线5px
tooltip: { ctx.lineDashOffset = 0;
textStyle: { } else {
fontSize: 12 // 线
}, ctx.setLineDash([]);
format: (item, category, index, opts) => { }
return `${category}\n${item.seriesName}: ${item.data}`
} //
}, config.chart.option.extra.render.series.line.call(this, canvas, config, series, index);
markLine: {
}, ctx.restore();
line: { }
width: 2, }
smooth: true }
} }
} };
};
}, },
// //