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

Data

Previous
Introduction
Next
Quick Start

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

G6 is a data-driven charting library, where data is one of the most important concepts. In G6, data is the core of the chart, and both display and interaction are based on data.

Common graph data formats include:CSV, DOT, GDF, GML, GraphML, GEXF etc。

G6 uses JSON format to describe the graph structure, which includes information about nodes and edges. Here is a simple JSON data example:

{
"nodes": [{ "id": "node1" }, { "id": "node2" }],
"edges": [{ "source": "node1", "target": "node2" }]
}

Compared to the other formats mentioned above, the JSON format has a more intuitive and understandable data structure. It is also more flexible, allowing for easy expansion of node and edge attributes.

It is a data exchange format widely supported by computers, so you do not have to worry about data format compatibility issues.

Data Structure

In G6, graph data consists of three parts: nodes (node data), edges (edge data), and combos (combo data). Each part corresponds to different elements in the graph, and their types and data determine how the graph is displayed.

interface GraphData {
nodes: NodeData[]; // Node data
edges?: EdgeData[]; // Edge data (optional)
combos?: ComboData[]; // Combo data (optional)
}

Node Data

A node is the basic building block of a graph and represents an entity within the graph. Each node has a unique id used to identify it, and nodes can also have data, styles, and states.

AttributeTypeDescription
Required idstringUnique identifier for the node, used to distinguish different nodes
typestringNode type. It can be the type of built-in Node, or the custom Node
dataObjectCustom data for the node, such as name, description, etc. Can be accessed in style mappings via callback functions
styleObjectNode style, including position, size, color, and other visual properties
statesstring[]Initial states for the node, such as selected, active, hover, etc.
combostring | nullID of the combo the node belongs to. Used to organize hierarchical relationships. If none, it is null
childrenstring[]Collection of child node IDs, used only in tree diagrams

Example:

{
"id": "node-1",
"type": "circle",
"data": { "name": "alice", "role": "Admin" },
"style": { "x": 100, "y": 200, "size": 32, "fill": "violet" },
"states": ["selected"],
"combo": null
}

Edge Data

An edge connects nodes and represents the relationship between them. Each edge is associated with two nodes (source and target), and edges themselves can have data, styles, and states. Edge data is often used to represent logical relationships, such as user connections in social networks or step flows in flowcharts.

AttributeTypeDescription
Required sourcestringSource node ID
Required targetstringTarget node ID
idstringUnique identifier for the edge. If not specified, id is automatically generated with the format ${source}-${target}
typestringEdge type.It can be the type of built-in Edge, or the custom Edge
dataObjectCustom data for the edge, accessible in style mappings via callback functions
styleObjectEdge style, including stroke color, line width, arrowhead, etc.
statesstring[]Initial states for the edge

Example:

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

Combo Data

Combos allow you to create a logical unit for multiple nodes, used for layering, grouping, or other structural purposes. A combo can contain child nodes or other combos, forming a nested structure.

AttributeTypeDescription
Required idstringUnique identifier for the combo
typestringCombo type.It can be the type of built-in Combo, or the custom Combo
dataObjectCustom data for the combo, accessible in style mappings via callback functions
styleObjectCombo style
statesstring[]Initial states for the combo
combostring | nullParent combo ID. If there is no parent combo, it is null

Example:

{
"id": "combo1",
"type": "circle",
"data": { "groupName": "Group A" },
"style": { "fill": "lightblue", "stroke": "blue", "collapsed": true },
"states": [],
"combo": null
}

Data Organization and Best Practices

To ensure correct rendering and interaction of the graph, it is recommended to organize the data according to G6's standard data structure. Each element (node, edge, combo) should contain a data field to store business data and custom properties.

  • Avoid using identifiers that conflict with internal G6 field names, such as id, type, style, etc., to prevent naming conflicts.
  • Store business data (such as user information, social network relationships, etc.) in the data field. This ensures flexibility and scalability of the data.

Example:

{
"nodes": [
{
"id": "node1",
"data": { "name": "Alice", "role": "Admin" }
},
{
"id": "node2",
"data": { "name": "Bob", "role": "User" }
}
],
"edges": [
{
"source": "node1",
"target": "node2",
"data": { "relationship": "friend" }
}
]
}

API

G6 provides a series of APIs to access and manipulate data, including:

  • getData
  • setData
  • updateData
  • getNodeData
  • getEdgeData
  • getComboData
  • addData
  • addNodeData
  • addEdgeData
  • addComboData
  • updateData
  • updateNodeData
  • updateEdgeData
  • updateComboData
  • removeData
  • removeNodeData
  • removeEdgeData
  • removeComboData

Through different APIs, you can conveniently access and manipulate graph data, performing operations such as adding, deleting, modifying, and querying the graph.

Use Remote Data

G6 does not provide functionality for data retrieval and parsing. For local JSON data, you can directly import and use it as follows:

import data from './path/to/data.json' assert { type: 'json' };

For remote data, you can use fetch or other networking libraries to retrieve the data:

fetch('https://path/to/data.json')
.then((res) => res.json())
.then((data) => {
// Use data
});