logo

G6

  • Docs
  • API
  • Playground
  • Community
  • Productsantv logo arrow
  • 5.0.45
  • Data
  • Canvas Operations
  • Element Operations
  • Graph Instance
  • Drawing and Rendering
  • Viewport Operations
  • Layout
  • Graph Options
  • Behavior
  • Plugin
  • Theme
  • Data Transformation
  • Event Listening
  • Coordinate Transformation
  • Export Image

Graph Options

Previous
Layout
Next
Behavior

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 of Graph Options

The options of a G6 graph instance control various aspects of the graph, including canvas settings, viewport properties, data, layout, styles, interaction behaviors, plugins, and more. By configuring these options appropriately, you can flexibly customize the appearance and behavior of the graph.

Options can be specified when creating a graph instance or dynamically modified at runtime through the API. Some basic configurations (such as devicePixelRatio, container) require destroying and recreating the graph instance to take effect after modification.

API Reference

Graph.getOptions()

Retrieve all configuration options of the current graph.

getOptions(): GraphOptions;

Return Value

  • Type: GraphOptions
  • Description: Complete configuration options of the current graph

Example

// Retrieve the current graph's options
const options = graph.getOptions();
console.log('Current graph options:', options);
// Retrieve specific options
console.log('Current canvas width:', options.width);
console.log('Current layout options:', options.layout);

Graph.setOptions(options)

Update the graph's configuration options.

setOptions(options: GraphOptions): void;

Parameters

ParameterDescriptionTypeDefaultRequired
optionsNew configuration optionsGraphOptions-✓

Note

⚠️ Attention: To update basic properties like devicePixelRatio, container, etc., you need to destroy the current graph instance and recreate it. Most other configurations can be dynamically updated.

Example 1: Basic Usage

// Update graph configuration
graph.setOptions({
width: 1000, // Update width
height: 800, // Update height
autoFit: true, // Enable auto-fit
animation: true, // Enable animation
});

Example 2: Update Theme

// Update graph theme configuration
graph.setOptions({
theme: {
type: 'dark', // Switch to dark theme
// Custom theme configuration
node: {
palette: ['#1AAF8B', '#F8E71C', '#8B572A', '#7ED321'],
},
edge: {
palette: ['#F5A623', '#F8E71C', '#8B572A', '#7ED321'],
},
},
});

Example 3: Update Layout Configuration

// Update layout configuration
graph.setOptions({
layout: {
type: 'force', // Switch to force-directed layout
preventOverlap: true,
nodeStrength: -50,
edgeStrength: 0.7,
},
});

Example 4: Update Default Node and Edge Configuration

// Update default style configuration for nodes and edges
graph.setOptions({
node: {
style: {
fill: '#91d5ff',
stroke: '#40a9ff',
lineWidth: 1,
radius: 10,
},
},
edge: {
style: {
stroke: '#91d5ff',
lineWidth: 2,
endArrow: true,
},
},
});

Type Definitions

GraphOptions

type GraphOptions = {
// Whether to enable zooming
enableZoom?: boolean;
// Whether to enable dragging
enableDrag?: boolean;
// Default style for nodes
defaultNodeStyle?: {
fill: string;
stroke: string;
};
// Additional configuration options for the graph
[configKey: string]: any;
};