g6js实现可拖拽关系图图表效果代码
代码语言:html
所属分类:图表
代码描述:g6js实现可拖拽关系图图表效果代码
下面为部分代码预览,完整代码请点击下载或在bfwstudio webide中打开
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> </head> <body> <div id="mountNode"></div> <script type="text/javascript" src="//repo.bfw.wiki/bfwrepo/js/g6.3.4.1.js"></script> <!-- 4.x and later versions --> <!-- <script src="https://gw.alipayobjects.com/os/lib/antv/g6/4.3.11/dist/g6.min.js"></script> --> <script> const graph = new G6.Graph({ container: 'mountNode', width: 800, height: 600, // 节点默认配置 defaultNode: { labelCfg: { style: { fill: '#fff', }, }, }, // 边默认配置 defaultEdge: { labelCfg: { autoRotate: true, }, }, // 节点在各状态下的样式 nodeStateStyles: { // hover 状态为 true 时的样式 hover: { fill: 'lightsteelblue', }, // click 状态为 true 时的样式 click: { stroke: '#000', lineWidth: 3, }, }, // 边在各状态下的样式 edgeStateStyles: { // click 状态为 true 时的样式 click: { stroke: 'steelblue', }, }, // 布局 layout: { type: 'force', linkDistance: 100, preventOverlap: true, nodeStrength: -30, edgeStrength: 0.1, }, // 内置交互 modes: { default: ['drag-canvas', 'zoom-canvas', 'drag-node'], }, }); const main = async () => { const response = await fetch( '//repo.bfw.wiki/bfwrepo/json/6cae02ab-4c29-44b2-b1fd-4005688febcb.json', ); const remoteData = await response.json(); const nodes = remoteData.nodes; const edges = remoteData.edges; nodes.forEach((node) => { if (!node.style) { node.style = {}; } node.style.lineWidth = 1; node.style.stroke = '#666'; node.style.fill = 'steelblue'; switch (node.class) { case 'c0': { node.type = 'circle'; node.size = 30; break;.........完整代码请登录后点击上方下载按钮下载查看
网友评论0