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

Edge Overview

Previous
Define Nodes with React
Next
Common Edge Configurations

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...

What is an Edge

An edge is one of the basic elements in a graph, used to connect two nodes or combos, representing the relationship between them. In G6, edges are directional, pointing from source to target, but you can configure them to hide the arrow to represent undirected connections.

You can create edges between any two nodes, combos, or between a node and a combo, and you can express different types of relationships by creating multiple edges.

G6 provides the following built-in edges:

  • line Straight line edge
  • polyline Polyline edge
  • quadratic Quadratic Bezier curve edge
  • cubic Cubic Bezier curve edge
  • cubicVertical Vertical cubic Bezier curve edge
  • cubicHorizontal Horizontal cubic Bezier curve edge

Data Structure

When defining an edge, you need to add an edges field to the graph's data object. Each edge is an object with the following structure:

AttributeDescriptionTypeDefaultRequired
sourceID of the starting node of the edgestring-✓
targetID of the target node of the edgestring-✓
idUnique identifier of the edgestring-
typeType of edge, name of built-in edge type or custom edge, such as line or polylinestring-
dataEdge data, used to store custom data of the edge, can be accessed in style mapping through callback functionsobject-
styleEdge style, including visual attributes like line color, width, arrow, etc.object-
statesInitial states of the edgestring[]-

An example of a data item in the edges array:

{
"source": "alice",
"target": "bob",
"type": "line",
"data": { "relationship": "friend", "strength": 5 },
"style": { "stroke": "green", "lineWidth": 2 },
"states": ["hover"]
}

Configuration Methods

There are three ways to configure edges, listed in order of priority from high to low:

  • Use graph.setEdge() for dynamic configuration
  • Global configuration when instantiating the graph
  • Dynamic attributes in data

These configuration methods can be used simultaneously. When there are the same configuration items, the method with higher priority will override the one with lower priority.

Using graph.setEdge()

You can dynamically set the style mapping logic of edges using graph.setEdge() after the graph instance is created.

This method needs to be called before graph.render() to take effect and has the highest priority.

graph.setEdge({
style: {
type: 'line',
style: { stroke: '#5CACEE', lineWidth: 2 },
},
});
graph.render();

Global Configuration When Instantiating the Graph

You can configure edge style mapping globally when instantiating the graph, and this configuration will take effect on all edges.

import { Graph } from '@antv/g6';
const graph = new Graph({
edge: {
type: 'line',
style: { stroke: '#5CACEE', lineWidth: 2 },
},
});

Dynamic Configuration in Data

If you need different configurations for different edges, you can write the configuration into the edge data. This configuration method can be directly written into the data in the form of the following code:

const data = {
edges: [
{
source: 'node-1',
target: 'node-2',
type: 'line',
style: { stroke: 'orange' },
},
],
};

Adjusting Priority

If you want the configuration in the data to have a higher priority than the global configuration, you can take the following approach:

const data = {
edges: [
{
source: 'node-1',
target: 'node-2',
type: 'line',
style: { stroke: 'orange' },
},
],
};
const graph = new Graph({
edge: {
type: 'line',
style: {
stroke: (d) => d.style.stroke || '#5CACEE',
lineWidth: 2,
},
},
});

Custom Edges

When built-in edges cannot meet the requirements, G6 provides powerful customization capabilities:

  • Extend built-in edges
  • Create entirely new edge types

Unlike combos, custom edges need to be registered before use. For detailed tutorials, please refer to the Custom Edge documentation.