Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

怎么改一下从服务器fetch异步取数据,我取下来没法更新graph? #26

Open
SeekPoint opened this issue Dec 16, 2022 · 0 comments

Comments

@SeekPoint
Copy link

import React, { useEffect, useState } from 'react';
import ReactDOM from 'react-dom';
import { data } from './data';
import G6 from '@antv/g6';

export default function () {
const ref = React.useRef(null);
let graph = null;

useEffect(() => {

const dataUrl = "http://127.0.0.1:8000/visg6/json_res";

fetch(dataUrl)  //fdata is a promise
    .then(response => response.json())
    .then(data => {
      setData(data.message)
      console.log("fetched data is:", data); //**能看到**
    },[]);
console.log('---yk--- from server:', data);// **并不会渲染,**


if (!graph) {
  graph = new G6.Graph({
    container: ReactDOM.findDOMNode(ref.current),
    width: 1200,
    height: 800,
    modes: {
      default: ['drag-canvas'],
    },
    layout: {
      type: 'dagre',
      direction: 'LR',
    },
    defaultNode: {
      type: 'node',
      labelCfg: {
        style: {
          fill: '#000000A6',
          fontSize: 10,
        },
      },
      style: {
        stroke: '#72CC4A',
        width: 150,
      },
    },
    defaultEdge: {
      type: 'polyline',
    },
  });
}
graph.data(data);
graph.render();

}, []);

return

;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant