From c0f0483df7fe850d2e2a887755a10c0f0b017473 Mon Sep 17 00:00:00 2001 From: duanhao Date: Thu, 7 Aug 2025 10:35:34 +0800 Subject: [PATCH] =?UTF-8?q?groupGraph=E7=BB=84=E4=BB=B6=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../GroupEvolution/component/groupGraph.vue | 27 ++++++++++++++++--- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/views/GroupEvolution/component/groupGraph.vue b/src/views/GroupEvolution/component/groupGraph.vue index 7dbbaf9..06a9f6e 100644 --- a/src/views/GroupEvolution/component/groupGraph.vue +++ b/src/views/GroupEvolution/component/groupGraph.vue @@ -174,7 +174,21 @@ const runForceLayout = () => { }) forceSimulator = curForceSimulator } +// 添加更新图表的函数 +const updateChart = (newGraphData) => { + if (!graphVis) { + initChart(); + return; + } + // 清除现有图表 + graphVis.clearAll(); + // 添加新数据 + graphVis.addGraph({ ...toRaw(newGraphData) }); + + // 重新运行力导向布局 + runForceLayout(); +} const initChart = () => { const getGroupCenters = (groupCount, width, height, radius = 200) => { // 三组分布在三角形顶点 @@ -229,10 +243,15 @@ const initChart = () => { graphVis.addGraph({ ...toRaw(graph.value) }) runForceLayout() } -onMounted(() => { - initChart() - -}) +watch( + graph, + (newValue) => { + if (newValue && Object.keys(newValue).length > 0) { + updateChart(newValue); + } + }, + { deep: true, immediate: true } +); onUnmounted(() => { if (graphVis) {