logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • XFlow
  • Productsantv logo arrow
  • 2.x
  • Introduction
  • Quickstart
  • Basic
    • Graph
    • Nodes
    • Edges
    • Connection Pile
    • Interaction
    • Events
    • Data Serialization
  • Intermediate
    • Connection Points
    • Tools
    • Group
    • React Nodes
    • Vue Nodes
    • Angular Nodes
    • HTML Nodes
  • Plugin
    • Graphic Transformations
    • Snapline
    • Clipboard
    • Keyboard
    • History
    • Selection Box
    • Scroller
    • Dnd
    • Mini Map
    • Stencil
    • Export
  • Upgrade to Version 2.x
  • Developer Tools

Quickstart

Previous
Introduction
Next
Graph

Resource

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-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

Installation

X6 is published on npm as @antv/x6.

# npm
$ npm install @antv/x6 --save
# yarn
$ yarn add @antv/x6

If using the umd package, you can use any of the following CDN.

  • https://unpkg.com/@antv/x6/dist/index.js
  • https://cdn.jsdelivr.net/npm/@antv/x6/dist/index.js
  • https://cdnjs.cloudflare.com/ajax/libs/antv-x6/2.0.0/index.js

Basic Usage

It's recommended to learn SVG Basics before you begin, and with some basic SVG knowledge in mind, let's start with a simple example to play with X6.

1. Init Graph

Creating a graph container on the page and then initializing the graph object, then you can set the graph style through configuration, such as the background color.

<div id="container"></div>
import { Graph } from '@antv/x6'
const graph = new Graph({
container: document.getElementById('container'),
width: 800,
height: 600,
background: {
color: '#F2F7FA',
},
})

2. Render nodes and edges

X6 supports json data, you can also use the attrs attribute to customize the styles of nodes and edges (like CSS).

3. Using the React Node

X6 supports using SVG and HTML to render node content. On this basis, we can also use React and Vue components to render nodes, which will be very convenient in the development process.

For example, we have a new requirement: add a right-click menu to the node. It would be more complicated to implement using SVG, We can easily implement it with react node. We can use the React render package @antv/x6-react-shape that comes with X6.

4. Using the Plugins

In addition to the basic element rendering capabilities, X6 also comes with a large number of built-in plugins for graph editing. Using these mature plugins, we can improve the development efficiency. For example, we add a snapline plugin to the graph, when a moving node is aligned with other nodes, the snapline will automatically appear.

import { Snapline } from '@antv/x6-plugin-snapline'
graph.use(
new Snapline({
enabled: true,
}),
)

5. Export the Data

In addition to using fromJSON to render JSON data to the graph, of course, there is also support for exporting the data from the graph width toJSON, so that we can serialize the graph data and store it to the server.

graph.toJSON()

That's the end of our demo. If you want to continue learning about some capabilities of X6, you can start reading from the Basic Tutorial.