From 87752f12e6ea2e7ddac479f808c9878046f5fd4b Mon Sep 17 00:00:00 2001 From: wangfq Date: Fri, 5 Jun 2026 15:03:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=9B=BE=E8=A1=A8=E8=A7=86=E5=9B=BE?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=BB=A7=E7=94=B5=E5=99=A8=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E7=8A=B6=E6=80=81=E7=B3=BB=E5=88=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 新增 buildRelaySeries() 函数构建继电器阶梯线系列 (type=line, step=end, 红色三角标记) - 新增第4 Y轴(继电器输出),刻度 0-3,标签解码为 无输出/存在信号/脉冲信号/存在+脉冲 - tooltip 中继电器值自动解码为可读文本 - grid right 扩大到 200px 容纳第4 Y轴 --- edc-web/app/static/js/test_data.js | 35 +++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/edc-web/app/static/js/test_data.js b/edc-web/app/static/js/test_data.js index facc6d5..89330a8 100644 --- a/edc-web/app/static/js/test_data.js +++ b/edc-web/app/static/js/test_data.js @@ -241,6 +241,27 @@ const CHART_SERIES = { ], }; +// 继电器系列(添加到任意视图的图表末尾) +function buildRelaySeries(records) { + return { + name: '继电器输出', + type: 'line', + step: 'end', + yAxisIndex: 3, + symbol: 'triangle', + symbolSize: 8, + lineStyle: { type: 'dotted', width: 2, color: '#e74c3c' }, + itemStyle: { color: '#e74c3c' }, + data: records.map(r => r.relay_code ?? null), + // tooltip 中显示解码后的文本 + tooltip: { + valueFormatter: function (value) { + return RELAY_MAP[value] || `未知(${value})`; + } + }, + }; +} + function toggleChart() { const container = document.getElementById('chart-container'); const btn = document.getElementById('btn-chart'); @@ -317,6 +338,9 @@ async function loadChart() { connectNulls: false, })); + // 添加继电器状态系列 + series.push(buildRelaySeries(records)); + // 渲染 ECharts if (chartInstance) chartInstance.dispose(); chartInstance = echarts.init(container); @@ -344,7 +368,7 @@ async function loadChart() { }, }, }, - grid: { left: 60, right: 140, top: 60, bottom: 80 }, + grid: { left: 60, right: 200, top: 60, bottom: 80 }, xAxis: { type: 'category', data: times, @@ -358,6 +382,15 @@ async function loadChart() { { type: 'value', name: '距离(mm)', nameTextStyle: { fontSize: 11 } }, { type: 'value', name: '速度(dm/s)',nameTextStyle: { fontSize: 11 }, offset: 80 }, + { type: 'value', name: '继电器输出', nameTextStyle: { fontSize: 11 }, + min: -0.5, max: 3.5, interval: 1, + offset: 160, + axisLabel: { + formatter: function (v) { + return RELAY_MAP[v] || ''; + }, + fontSize: 10, + }}, ], dataZoom: [ { type: 'slider', start: 0, end: 100, height: 20, bottom: 30 },