图例container无效,changeData报错 #5581
DIVADING posted onGitHub
Describe the bug
在图例正常设置并且已经显示在页面上时,打印legend.container会显示undefined,legend.changeData会报以下错误:
Your Example Website or App
如有需要请告诉我 我再提供
Steps to Reproduce the Bug or Issue
const legend = new G6.Legend({ data: { nodes: [], edges: [] }, align: 'center', layout: 'horizontal', // vertical position: 'bottom-left', vertiSep: 12, horiSep: 24, offsetY: -24, padding: [4, 16, 8, 16], containerStyle: { fill: '#ccc', lineWidth: 1, }, title: 'Legend', titleConfig: { position: 'left', offsetX: 0, offsetY: 12, }, filter: { enable: true, multiple: true, trigger: 'click', graphActiveState: 'activeByLegend', graphInactiveState: 'inactiveByLegend', filterFunctions: {}, }, });
// 这里会log undefined console.log( '%c [ ]-101', 'font-size:13px; background:#b83e89; color:#fc82cd;', legend.getContainer(), );
创建g6实例: const createNewG6Graph = () => { const minimap = new Minimap({ size: [100, 100], className: 'minimap', type: 'delegate', }); const newG6Graph = new G6.Graph({ container: 'graph-container', fitView: true, modes: { default: [ 'zoom-canvas', 'drag-canvas', 'drag-node', // { type: 'activate-relations', activeState: 'active' }, ], }, layout: { type: 'fruchterman', animate: false, preventOverlap: true, nodeSize: defaultNodeSize, gravity: 10, speed: 100, }, plugins: [minimap, tooltip, legend], }); };
html结构: <div ref={ref} id={'g-graph'}> <div id={'graph-container'} style={{ height: 800, width: '100%', display: 'flex' }} ></div> </div>
Expected behavior
如何在react正确使用图例并随时更新图例数据?
Screenshots or Videos
No response
Platform
- OS: macOS
- Browser: Chrome
- Version: 122.0.6261.112
Additional context
No response