antvis/G6

Cannot read properties of undefined (reading 'Graph') #6049

anyone0034 posted onGitHub



import React, { useEffect, useRef } from 'react'



import G6 from '@antv/g6';

const TestG6 = () => {
    const containerRef = useRef<HTMLDivElement>(null);
    const graphRef = useRef<any>();

    useEffect(() => {
        initDraw()
    }, [])

    const initDraw = () => {
        graphRef.current = new G6.Graph({
            linkCenter: true,
            container: containerRef.current || '',
            height: 800,
            defaultNode: {
                size: 20,
                style: {
                    fill: '#C6E5FF',
                    stroke: '#5B8FF9',
                    lineWidth: 0.3,
                },
                labelCfg: {
                    style: {
                        fontSize: 12,
                    },
                    position: 'bottom',
                    offset: 1,
                },
            },
            defaultEdge: {
                style: {
                    lineWidth: 2,
                    color: '#000',
                    labelCfg: {
                        autoRotate: true,
                        refY: 5,
                        style: {
                            fill: '#000'
                        }
                    },
                    endArrow: {
                        fill: '#000',
                        path: G6.Arrow.triangle(10, 12, 25),
                        d: 25
                    }
                }
            }
        });

        const data = {
            nodes: [
                { id: 'node1', x: 100, y: 100, label: 'Node 1' },
                { id: 'node2', x: 300, y: 100, label: 'Node 2' },
            ],
            edges: [
                { source: 'node1', target: 'node2', label: 'Edge 1' },
            ],
        };

        // 渲染图表
        graphRef.current.data(data);
        graphRef.current.render();
    }

    return (
        <div className='ModalgraphContainer' ref={containerRef} id="graphContainer"></div>
    )
}
export default TestG6;

111

posted by anyone0034 9 months ago

11111

posted by anyone0034 9 months ago

同问

posted by ChenLeoXX 9 months ago

最新版本好像有这个问题,我安装最新版本的G6也这样,换成@4.8.24版本就可以正常加载了

posted by YUZHANGHENG 6 months ago

@anyone0034 你好,请问有找到解决方法吗?我是5.x版本遇到这个问题的

posted by TZZack 5 months ago

@anyone0034 你好,请问有找到解决方法吗?我是5.x版本遇到这个问题的

没事了,不是G6的问题,是webpack构建时做了些特殊处理导致,具体看这里 https://github.com/antvis/G6/discussions/6504

posted by TZZack 5 months ago

Fund this Issue

$0.00
Funded

Pull requests