// 数据数组声明
let AUCarr = Array(100).fill(null);
let ACCarr = Array(100).fill(null);
let dataPointIndex = 0; // 跟踪当前数据点索引
let dataInterval = null;
let accChart = null;
let aucChart = null;
// 新增:epoch数组,1~400
let epochArr = Array.from({length: 100}, (_, i) => (i + 1) * 4);
console.log(epochArr);
// 基础图表配置
const baseConfig = {
chart: {
type: 'line',
width: '100%',
height: '400px',
animations: {
enabled: false
},
toolbar: {
show: false
},
events: {
mounted: function(ctx) {
// 图表加载完成后调整布局
ctx.updateOptions({
grid: {
padding: {
bottom: 30
}
}
}, false, false);
}
}
},
grid: {
padding: {
left: 20,
right: 20,
bottom: 30
}
},
dataLabels: {
enabled: false
},
stroke: {
curve: 'smooth',
width: 3
},
markers: {
size: 6,
shape: 'circle',
strokeWidth: 2,
strokeColor: '#fff'
},
yaxis: {
min: 0,
max: 1,
labels: {
formatter: function(value) {
return value.toFixed(2);
}
}
},
xaxis: {
labels: {
style: {
fontSize: '12px',
cssClass: 'apexcharts-xaxis-label'
},
offsetY: 5,
show: true,
tickAmount: 20
},
axisBorder: {
show: true
},
axisTicks: {
show: true
}
},
tooltip: {
enabled: true,
}
};
// ACC图表配置
const accoptions = {
...baseConfig,
series: [{
name: 'ACC',
data: ACCarr,
}],
labels: {
show: true, // 确保显示标签
style: {
fontSize: '12px'
},
offsetY: 5
},
xaxis: {
type: 'category', // 关键:强制按 category 处理
categories: epochArr,
tickAmount: 0, // 关闭自动刻度
title: { text: 'epoch', style: { fontSize: '14px', fontWeight: 600 } },
labels: {
style: { fontSize: '12px' },
offsetY: 8,
formatter: function (value, index) {
// epochArr 每 4 位出现一次,即 20 epoch
return index % 4 === 0 ? value : '';
}
}
},
colors: ['#00E396'],
markers: {
...baseConfig.markers,
fillColors: ['#00E396']
}
};
// AUC图表配置
const aucoptions = {
...baseConfig,
series: [{
name: 'AUC',
data: AUCarr,
}],
xaxis: {
type: 'category', // 关键:强制按 category 处理
categories: epochArr,
tickAmount: 0, // 关闭自动刻度
title: { text: 'epoch', style: { fontSize: '14px', fontWeight: 600 } },
labels: {
style: { fontSize: '12px' },
offsetY: 8,
formatter: function (value, index) {
// epochArr 每 4 位出现一次,即 20 epoch
return index % 5 === 0 ? value : '';
}
}
},
colors: ['#FEB019'],
markers: {
...baseConfig.markers,
fillColors: ['#FEB019']
}
};
// 数据数组
const ACCarrlist = [
// 0–59 非线性增长 + 波动
0.0010,0.0083,0.0174,0.0284,0.0413,0.0562,0.0729,0.0915,0.1119,0.1340,
0.1577,0.1828,0.2092,0.2367,0.2651,0.2942,0.3238,0.3537,0.3836,0.4133,
0.4425,0.4709,0.4983,0.5244,0.5490,0.5719,0.5929,0.6118,0.6285,0.6430,
0.6552,0.6652,0.6731,0.6790,0.6831,0.6856,0.6966,0.6863,0.6950,0.6928,
0.7000,0.7068,0.7134,0.7201,0.7272,0.7349,0.7434,0.7529,0.7695,0.7754,
0.7786,0.7832,0.7992,0.7966,0.7954,0.8055,0.8069,0.8195,0.8133,0.8281,
0.8239,0.8305,0.8478,0.8556,0.8538,0.8621,0.8804,0.9084,0.9160,0.9228,
// 70–99 平稳
0.920, 0.920, 0.920, 0.920, 0.920,
0.920, 0.920, 0.920, 0.920, 0.920,
0.920, 0.920, 0.920, 0.920, 0.920,
0.920, 0.920, 0.920, 0.920, 0.920,
0.920, 0.920, 0.920, 0.920, 0.920,
0.920, 0.920, 0.920, 0.920, 0.920
];
const AUCarrlist = [
// 0–59 非线性增长 + 波动
0.0010,0.0089,0.0191,0.0316,0.0463,0.0632,0.0823,0.1035,0.1267,0.1517,
0.1784,0.2066,0.2361,0.2667,0.2982,0.3303,0.3628,0.3955,0.4280,0.4602,
0.4918,0.5225,0.5520,0.5800,0.6063,0.6306,0.6528,0.6728,0.6804,0.6856,
0.7084,0.7089,0.7173,0.7237,0.7484,0.7415,0.7433,0.7540,0.7539,0.7632,
0.7622,0.7811,0.8002,0.8298,0.8401,0.8613,0.8737,0.8754,0.8726,0.8893,
0.8975,0.9072,0.9184,0.9210,0.9349,0.9400,0.9462,0.9534,0.9514,0.9600,
// 60–99 平稳
0.976, 0.976, 0.976, 0.976, 0.976,
0.976, 0.976, 0.976, 0.976, 0.976,
0.976, 0.976, 0.976, 0.976, 0.976,
0.976, 0.976, 0.976, 0.976, 0.976,
0.976, 0.976, 0.976, 0.976, 0.976,
0.976, 0.976, 0.976, 0.976, 0.976,
0.976, 0.976, 0.976, 0.976, 0.976,
0.976, 0.976, 0.976, 0.976, 0.976
];
// 数据生成函数
function generateNextDataPoint() {
if (dataPointIndex >= ACCarrlist.length || dataPointIndex >= epochArr.length) {
clearInterval(dataInterval);
dataInterval = null;
return;
}
// 获取当前数据点
const aucValue = parseFloat(AUCarrlist[dataPointIndex].toFixed(4));
const accValue = parseFloat(ACCarrlist[dataPointIndex].toFixed(4));
AUCarr[dataPointIndex] = aucValue;
ACCarr[dataPointIndex] = accValue;
// 更新图表
accChart.updateSeries([{ data: ACCarr }], false);
aucChart.updateSeries([{ data: AUCarr }], false);
dataPointIndex++;
}
// 开始训练按钮事件
function startTraining() {
// 重置数据状态
AUCarr = Array(100).fill(null);
ACCarr = Array(100).fill(null);
dataPointIndex = 0;
// 清除旧定时器
if (dataInterval) {
clearInterval(dataInterval);
dataInterval = null;
}
// 初始化或重置图表
if (!accChart) {
accChart = new ApexCharts(document.querySelector('#acc'), accoptions);
accChart.render();
} else {
accChart.updateSeries([{ data: ACCarr }], false);
}
if (!aucChart) {
aucChart = new ApexCharts(document.querySelector('#auc'), aucoptions);
aucChart.render();
} else {
aucChart.updateSeries([{ data: AUCarr }], false);
}
// 立即生成第一个数据点
generateNextDataPoint();
// 设置定时器生成后续数据点
dataInterval = setInterval(generateNextDataPoint, 300);
}为什么图表的横坐标没有正常显示