任何人都可以幫我更新模式嗎?現在這就是我給我的圖表 React 組件新資料時得到的......舊的保留......這是我的代碼
uj5u.com熱心網友回復:
我認為您的問題出在 GraphGenerator.jsx 上:
svgRef.current = d3.select('#viz')
.attr('width', svgWidth)
.attr('height', svgHeight)
.append('g') // a new group is appended
您g每次都附加一個新元素。該新元素沒有資料,因此在連接中沒有洗掉或更新任何內容。如果你洗掉.append('g')它應該作業。
編輯:
在您使用的節點創建中進一步向下:
const circles = svgRef.current
.selectAll()
.data(NODES)
.join("g");
您沒有選擇任何內容,因此無法更新任何內容。在那里使用它:
const circles = svgRef.current
.selectAll('.node')
.data(NODES)
.join("g")
.classed('node',true)
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/366582.html
標籤:d3.js
