logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • Productsantv logo arrow
  • 3.x
  • Introduction
  • Quickstart
  • Basic
    • Graph
    • Nodes
    • Edges
    • Ports
    • Interaction
    • Events
    • Data Serialization
    • Animation
  • 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 3.x
  • Developer Tools

Export

Previous
Stencil
Next
Upgrade to 3.x

Resource

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

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference
weavefoxWeaveFox-AI Developer Community

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
weavefoxWeaveFox-AI Coding Assistant
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

This chapter mainly introduces the knowledge of the export plugin. By reading, you can learn about

  • How to export the canvas content in image format

Usage

You can export the canvas content as images via the Export plugin. Example:

import { Graph, Export } from '@antv/x6'
const graph = new Graph({
background: {
color: '#F2F7FA',
},
})
graph.use(new Export())

API

graph.exportSVG(...)

exportSVG(fileName?: string, options?: Export.ToSVGOptions): void

fileName is the name of the file, defaulting to chart. Export.ToSVGOptions is described as follows:

Property NameTypeDefault ValueRequiredDescription
preserveDimensionsboolean | Size-Controls the exported SVG size. When unset, width/height are 100%; when true, they are auto-calculated to the actual content size; you can also pass { width, height } to explicitly set the export size.
viewBoxRectangleLike-Sets the viewBox of the exported SVG.
copyStylesbooleantrueWhether to copy styles from external stylesheets. When enabled, computed style differences of nodes are inlined into the exported SVG to keep visuals consistent with the page; this adds export time. If you prefer speed or styles are set via attrs, set to false and pair with stylesheet to inject necessary CSS.
stylesheetstring-Custom stylesheet.
serializeImagesbooleantrueWhether to convert the xlink:href/href of image elements to DataURI (forced for PNG/JPEG).
beforeSerialize(this: Graph, svg: SVGSVGElement) => any-You can call beforeSerialize to modify the SVG string before exporting it.

graph.exportPNG(...)

exportPNG(fileName?: string, options?: Export.ToImageOptions): void

fileName is the name of the file, defaulting to chart. Export.ToImageOptions inherits from the above Export.ToSVGOptions and has the following additional configurations:

Property NameTypeDefault ValueRequiredDescription
widthnumber-Width of the exported image.
heightnumber-Height of the exported image.
rationumber1Scale factor (e.g., device pixel ratio) used to compute export resolution.
backgroundColorstring-Background color of the exported image, defaults to white.
paddingNumberExt.SideOptions-Padding for the image.
qualitynumber-Image quality (0–1). If out of range, the default value 0.92 is used.

graph.exportJPEG(...)

exportJPEG(fileName?: string, options?: Export.ToImageOptions): void

graph.toSVG(...)

toSVG(callback: (dataUri: string) => any, options?: Export.ToSVGOptions): void

graph.toPNG(...)

toPNG(callback: (dataUri: string) => any, options?: Export.ToImageOptions): void

graph.toJPEG(...)

toJPEG(callback: (dataUri: string) => any, options?: Export.ToImageOptions): void