logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.47
  • Introduction
  • Data
  • Getting Started
    • Quick Start
    • Installation
    • Integration
      • react
      • vue
      • angular
    • Step-by-step guide
  • Graph
    • Extensions En
    • Graph
    • Options
    • extension
  • Element
    • Element Overview
    • Element State
    • Node
      • Node Overview
      • Build-in Node
        • Common Node Configurations
        • Diamond
        • Donut
        • Ellipse
        • Hexagon
        • Html
        • Image
        • Rect
        • Star
        • Triangle
        • Circle
      • Custom Node
      • Define Nodes with React
    • Edge
      • Edge Overview
      • Build-in Edge
        • Common Edge Configurations
        • Cubic Bezier Curve
        • CubicHorizontal Bezier Curve
        • CubicVertical Bezier Curve
        • Line
        • Polyline
        • Quadratic Bezier Curve
      • Custom Edge
    • Combo
      • Combo Overview
      • Build-in Combo
        • Circle
        • Combo Configuration Options
        • Rect
      • Custom Combo
    • Shape
      • Shape and KeyShape
      • Atomic Shapes and Their Properties
      • Design and Implementation of Composite Shape
  • Layout
    • Layout Overview
    • Build-in Layout
      • 3D Force-Directed Layout
      • AntvDagre Layout
      • Circular Layout
      • ComboCombined Layout
      • Common Layout Configuration Options
      • CompactBox
      • Concentric Layout
      • D3 Force-Directed Layout
      • Dagre Layout
      • Dendrogram Layout
      • Fishbone Layout
      • Force Force-directed Layout
      • ForceAtlas2 Force-directed Layout
      • Fruchterman Force-directed Layout
      • Grid Layout
      • Indented Tree
      • MDS High-dimensional Data Dimensionality Reduction Layout
      • Mindmap Tree
      • Radial Layout
      • Random Layout
      • Snake Layout
    • Custom Layout
  • Behavior
    • Behavior Overview
    • Build-in Behavior
      • AutoAdaptLabel
      • BrushSelect
      • ClickSelect
      • CollapseExpand
      • CreateEdge
      • DragCanvas
      • DragElement
      • DragElementForce
      • FixElementSize
      • FocusElement
      • HoverActivate
      • LassoSelect
      • OptimizeViewportTransform
      • ScrollCanvas
      • ZoomCanvas
    • Custom Behavior
  • Plugin
    • Plugin Overview
    • Build-in Plugin
      • Background
      • BubbleSets
      • Contextmenu
      • EdgeBundling
      • EdgeFilterLens
      • Fisheye
      • Fullscreen
      • GridLine
      • History
      • Hull
      • Legend
      • Minimap
      • Snapline
      • Timebar
      • Toolbar
      • Tooltip
      • Watermark
    • Custom Plugin
  • Transform
    • Data Transformation Overview
    • Build-in Transform
      • MapNodeSize
      • PlaceRadialLabels
      • ProcessParallelEdges
    • Custom Transform
  • Theme
    • Theme Overview
    • Custom Theme
    • Palette
    • Custom Palette
  • Animation
    • Animation Overview
    • Custom Animation
  • Further Reading
    • Event
    • renderer
    • coordinate
    • download-image
    • Using Iconfont
    • Use 3D
    • Bundle Project
  • What's new
    • Feature
    • Upgrade To 5.0
  • FAQ
  • contribute

CreateEdge

Previous
CollapseExpand
Next
DragCanvas

Resources

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-互动图形解决方案
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Overview

CreateEdge is a built-in behavior in G6 for interactively creating edges on the canvas. After the user triggers the behavior (click or drag), the edge will follow the mouse movement and connect to the target node to complete the creation. If canceled, it will be automatically removed.

Additionally, this behavior supports customizing the style of the edge, such as color, line style, arrow, etc., to meet different visualization needs.

The elements that can be connected by this behavior are node and combo.

Usage Scenarios

This behavior is mainly used for:

  • Visualization scenarios that require interactive creation of connections between nodes, such as flowcharts, knowledge graphs, etc.

Online Experience

createGraph(
{
data: {
nodes: [
{ id: 'node1', combo: 'combo1', style: { x: 250, y: 150 } },
{ id: 'node2', combo: 'combo1', style: { x: 350, y: 150 } },
{ id: 'node3', combo: 'combo2', style: { x: 250, y: 300 } },
],
edges: [],
combos: [
{ id: 'combo1', combo: 'combo2' },
{ id: 'combo2', style: {} },
],
},
node: { style: { fill: '#873bf4' } },
edge: { style: { stroke: '#8b9baf' } },
behaviors: [
{
type: 'create-edge',
key: 'create-edge',
},
],
plugins: [{ type: 'grid-line', size: 30 }],
animation: true,
},
{ width: 600, height: 400 },
(gui, graph) => {
const options = {
key: 'create-edge',
type: 'create-edge',
animation: true,
enable: true,
trigger: 'drag',
};
const optionFolder = gui.addFolder('CollapseExpand Options');
optionFolder.add(options, 'type').disable(true);
optionFolder.add(options, 'animation');
optionFolder.add(options, 'enable');
optionFolder.add(options, 'trigger', ['drag', 'click']);
optionFolder.onChange(({ property, value }) => {
graph.updateBehavior({
key: 'create-edge',
[property]: value,
});
graph.render();
});
},
);

Basic Usage

Add this behavior in the graph configuration

// Use default configuration
const graph = new Graph({
// Other configurations...
behaviors: ['create-edge'], // Directly add, use default configuration
});
// Or use custom configuration
const graph = new Graph({
// Other configurations
behaviors: [
{
type: 'create-edge',
trigger: 'click', // Behavior configuration, create edge by clicking
style: {}, // Custom edge style
},
],
});

Configuration Options

OptionDescriptionTypeDefaultRequired
typeBehavior type namestringcreate-edge√
triggerThe way to trigger the creation of a new edge: click means click to trigger; drag means drag to triggerclick | dragdrag
enableWhether to enable this behaviorboolean | ((event: Event) => boolean)true
onCreateCallback function for creating an edge, returns edge data(edge: EdgeData) => EdgeData-
onFinishCallback function for successfully creating an edge(edge: EdgeData) => void-
styleStyle of the newly created edge, configuration optionsSee below-

style

Configure the style of the newly created edge, for detailed configuration options, please refer to Element - Edge - General Edge Properties - Style

{
"style": {
"stroke": "red",
"lineWidth": 2
}
}

Code Examples

Basic Edge Creation Function

const graph = new Graph({
container: 'container',
width: 800,
height: 600,
behaviors: ['create-edge'],
});

Custom Edge Creation Function

const graph = new Graph({
// Other configurations,
behaviors: [
{
type: 'create-edge',
style: {
stroke: 'red',
lineWidth: 3,
},
},
],
});

Create Edge by Clicking

const graph = new Graph({
// Other configurations
behaviors: [
{
type: 'create-edge',
trigger: 'click',
},
],
});

Practical Example