syncfusion-react-diagram
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseSyncfusion React Diagram
Syncfusion React Diagram
The Syncfusion React Diagram component enables building rich, interactive diagrams including flowcharts, organizational charts, BPMN process flows, UML diagrams, mind maps, and network diagrams. It renders using SVG and supports extensive customization through nodes, connectors, ports, annotations, layouts, and data binding.
Syncfusion React Diagram组件可用于构建丰富的交互式图表,包括流程图、组织结构图、BPMN流程流、UML图、思维导图和网络图。它使用SVG渲染,并支持通过节点、连接器、端口、注释、布局和数据绑定进行广泛的自定义。
Table of Contents
目录
When to Use This Skill
何时使用该技能
Use this skill when users need to:
- Build flowcharts representing processes, decision trees, or workflows
- Create org charts from hierarchical or flat data sources
- Model BPMN diagrams with activities, events, gateways, and flows
- Draw UML diagrams including class diagrams and sequence diagrams
- Visualize mind maps or radial layouts from data
- Design network/entity diagrams with nodes and relationship connectors
- Implement swimlane diagrams with lanes and phases
- Drag and drop shapes from a symbol palette onto a canvas
- Bind data to automatically generate diagram structure
- Serialize and restore diagram state as JSON
- Export or print diagram content as image/SVG
当用户需要以下功能时,可使用该技能:
- 构建流程图:表示流程、决策树或工作流
- 创建组织结构图:从分层或扁平数据源生成
- 建模BPMN图表:包含活动、事件、网关和流
- 绘制UML图表:包括类图和序列图
- 可视化思维导图:从数据源生成放射状布局
- 设计网络/实体图表:包含节点和关系连接器
- 实现泳道图:包含泳道和阶段
- 从符号面板拖拽形状:到画布上
- 数据绑定:自动生成图表结构
- 序列化与恢复:将图表状态保存为JSON
- 导出或打印:将图表内容导出为图片/SVG或打印
Important: API Verification Required
重要提示:需验证API
API Verification Required: Always verify API class names, properties, and signatures by reading reference files () BEFORE generating code examples. Do not assume or infer class names.
references/*.md需验证API:在生成代码示例之前,请务必通过参考文件()验证API类名、属性和签名。请勿假设或推断类名。
references/*.mdComponent Overview
组件概述
The Diagram component is built around:
- Nodes — Graphical shapes (rectangles, circles, flow shapes, custom) placed on the canvas
- Connectors — Lines/arrows linking nodes or freestanding points
- Annotations — Text labels attached to nodes or connectors
- Ports — Named connection points on nodes for precise connector anchoring
- Layouts — Automatic arrangement algorithms (hierarchical, org-chart, mindmap, radial, flowchart)
- Symbol Palette — Sidebar of draggable shape symbols
- Module System — Opt-in feature modules (directive) to keep bundle size lean
Inject
All diagram elements are rendered using SVG for crisp, resolution-independent graphics.
图表组件围绕以下核心元素构建:
- 节点 — 放置在画布上的图形形状(矩形、圆形、流程形状、自定义形状)
- 连接器 — 连接节点或独立点的线条/箭头
- 注释 — 附加到节点或连接器的文本标签
- 端口 — 节点上的命名连接点,用于精确锚定连接器
- 布局 — 自动排列算法(分层、组织结构图、思维导图、放射状、流程图)
- 符号面板 — 可拖拽形状符号的侧边栏
- 模块系统 — 可选功能模块(指令),用于减小包体积
Inject
所有图表元素均使用SVG渲染,以实现清晰、与分辨率无关的图形效果。
Documentation and Navigation Guide
文档与导航指南
Getting Started
快速入门
📄 Read: references/getting-started.md
When to read:
- First-time setup of the Diagram component
- Installing packages, CSS imports, and theme configuration
- Creating a minimal
DiagramComponent - Understanding the module system
Inject - Next.js or Preact integration
Covers:
- npm install and dependencies
- Vite/CRA project setup
- CSS theme import paths
- Basic with
DiagramComponentandnodesconnectors - Module injection with
<Inject services={[...]} /> - Next.js and Preact usage notes
📄 阅读:references/getting-started.md
阅读时机:
- 首次设置Diagram组件
- 安装包、CSS导入和主题配置
- 创建最小化的
DiagramComponent - 理解模块系统
Inject - Next.js或Preact集成
涵盖内容:
- npm安装与依赖
- Vite/CRA项目设置
- CSS主题导入路径
- 包含和
nodes的基础connectorsDiagramComponent - 使用进行模块注入
<Inject services={[...]} /> - Next.js和Preact使用说明
Nodes
节点
📄 Read: references/nodes.md
When to read:
- Adding, positioning, and sizing nodes
- Customizing node appearance (fill, stroke, shadow)
- Working with node shapes (Flow, Basic, Path, Image, HTML)
- Handling node events (click, drag, resize)
- Expanding/collapsing nodes at runtime
- Setting default node properties via
getNodeDefaults
Covers:
- Creating nodes via collection
nodes - /
offsetX,offsetY/widthpositioningheight - Adding/removing nodes at runtime (,
diagram.add)diagram.remove - Style properties (fill, strokeColor, opacity, gradient)
- pattern for consistent styling
getNodeDefaults - Node expand/collapse with /
expandIconcollapseIcon - Node interaction events
📄 阅读:references/nodes.md
阅读时机:
- 添加、定位和调整节点大小
- 自定义节点外观(填充、描边、阴影)
- 使用节点形状(流程、基础、路径、图片、HTML)
- 处理节点事件(点击、拖拽、调整大小)
- 在运行时展开/折叠节点
- 通过设置默认节点属性
getNodeDefaults
涵盖内容:
- 通过集合创建节点
nodes - /
offsetX、offsetY/width定位height - 在运行时添加/删除节点(、
diagram.add)diagram.remove - 样式属性(填充、描边颜色、透明度、渐变)
- 模式:实现一致的样式
getNodeDefaults - 使用/
expandIcon实现节点展开/折叠collapseIcon - 节点交互事件
Connectors
连接器
📄 Read: references/connectors.md
When to read:
- Drawing lines/arrows between nodes or freestanding points
- Choosing connector type (Straight, Orthogonal, Bezier)
- Configuring connector segments and routing
- Customizing decorator (arrow) shapes
- Setting /
sourceIDto link nodestargetID - Setting for consistent styling
getConnectorDefaults
Covers:
- Connector types: ,
Straight,OrthogonalBezier - /
sourcePointfor freestanding connectorstargetPoint - /
sourceIDfor node-to-node connectionstargetID - Multiple segment configuration
- Bezier control points and segment edit orientation
- Arrow/decorator customization
- Connector events and interaction
- pattern
getConnectorDefaults
📄 阅读:references/connectors.md
阅读时机:
- 在节点或独立点之间绘制线条/箭头
- 选择连接器类型(直线、正交、贝塞尔曲线)
- 配置连接器段和路由
- 自定义装饰器(箭头)形状
- 设置/
sourceID连接节点targetID - 使用实现一致的样式
getConnectorDefaults
涵盖内容:
- 连接器类型:、
Straight、OrthogonalBezier - 独立连接器的/
sourcePointtargetPoint - 节点间连接的/
sourceIDtargetID - 多段配置
- 贝塞尔曲线控制点和段编辑方向
- 箭头/装饰器自定义
- 连接器事件与交互
- 模式
getConnectorDefaults
Labels and Annotations
标签与注释
📄 Read: references/labels-and-annotations.md
When to read:
- Adding text labels to nodes or connectors
- Styling annotation text (font, color, bold, alignment)
- Making labels draggable or editable
- Positioning labels relative to nodes/connectors
- Handling label-specific events
Covers:
- array on nodes and connectors
annotations - Label ,
content,style,offsetalignment - Node labels vs. connector labels
- Label interaction (edit on double-click, drag)
- Label appearance (background, border, padding)
- Label events
📄 阅读:references/labels-and-annotations.md
阅读时机:
- 为节点或连接器添加文本标签
- 注释文本样式设置(字体、颜色、加粗、对齐)
- 使标签可拖拽或编辑
- 相对于节点/连接器定位标签
- 处理标签特定事件
涵盖内容:
- 节点和连接器上的数组
annotations - 标签的、
content、style、offsetalignment - 节点标签与连接器标签的区别
- 标签交互(双击编辑、拖拽)
- 标签外观(背景、边框、内边距)
- 标签事件
Ports
端口
📄 Read: references/ports.md
When to read:
- Creating named connection points on nodes
- Controlling where connectors attach to a node
- Styling and positioning ports
- Restricting connector connections to specific ports
- Handling port interaction events
Covers:
- Port types and array on nodes
ports - Port positioning (,
offset)alignment - Port appearance (shape, fill, stroke)
- Connecting connectors to specific ports via /
sourcePortIDtargetPortID - Port interaction and visibility options
- Port events
📄 阅读:references/ports.md
阅读时机:
- 在节点上创建命名连接点
- 控制连接器与节点的附着位置
- 样式设置与端口定位
- 限制连接器仅连接到特定端口
- 处理端口交互事件
涵盖内容:
- 端口类型和节点上的数组
ports - 端口定位(、
offset)alignment - 端口外观(形状、填充、描边)
- 通过/
sourcePortID将连接器连接到特定端口targetPortID - 端口交互与可见性选项
- 端口事件
Shapes and Styles
形状与样式
📄 Read: references/shapes-and-styles.md
When to read:
- Choosing the right shape type (Flow, Basic, Path, Image, HTML, Native SVG)
- Applying fill colors, gradients, and stroke styles
- Customizing node appearance with CSS or themes
- Understanding shape property structure
Covers:
- options:
shape.type,Flow,Basic,Path,Image,HTMLNative - Flowchart shape values (Terminator, Process, Decision, etc.)
- Basic shape values (Rectangle, Ellipse, Diamond, etc.)
- Style properties: ,
fill,strokeColor,strokeWidth,strokeDashArrayopacity - Linear and radial gradients
- Shadow effect
- CSS class-based styling
📄 阅读:references/shapes-and-styles.md
阅读时机:
- 选择合适的形状类型(流程、基础、路径、图片、HTML、原生SVG)
- 应用填充颜色、渐变和描边样式
- 使用CSS或主题自定义节点外观
- 理解形状属性结构
涵盖内容:
- 选项:
shape.type、Flow、Basic、Path、Image、HTMLNative - 流程图形状值(终止符、流程、决策等)
- 基础形状值(矩形、椭圆、菱形等)
- 样式属性:、
fill、strokeColor、strokeWidth、strokeDashArrayopacity - 线性和径向渐变
- 阴影效果
- 基于CSS类的样式
BPMN Diagrams
BPMN图表
📄 Read: references/bpmn-diagrams.md
When to read:
- Modeling business process flows using BPMN notation
- Using BPMN-specific shapes (activities, events, gateways)
- Drawing sequence flows, message flows, associations
- Adding data objects, data sources, text annotations, and groups
Covers:
- module injection
BpmnDiagrams - BPMN shape type:
shape.type = 'Bpmn' - Activities: Task types, Subprocess, Expanded Subprocess
- Events: Start, End, Intermediate events and their triggers
- Gateways: Exclusive, Parallel, Inclusive, Complex
- Flows: Sequence, Message, Association
- Data objects and data sources
- BPMN groups and text annotations
📄 阅读:references/bpmn-diagrams.md
阅读时机:
- 使用BPMN符号建模业务流程
- 使用BPMN特定形状(活动、事件、网关)
- 绘制序列流、消息流、关联
- 添加数据对象、数据源、文本注释和组
涵盖内容:
- 模块注入
BpmnDiagrams - BPMN形状类型:
shape.type = 'Bpmn' - 活动:任务类型、子流程、展开的子流程
- 事件:开始、结束、中间事件及其触发器
- 网关:排他、并行、包容、复杂
- 流:序列、消息、关联
- 数据对象和数据源
- BPMN组和文本注释
UML Diagrams
UML图表
📄 Read: references/uml-diagrams.md
When to read:
- Building UML class diagrams with attributes and methods
- Modeling relationships (association, generalization, dependency)
- Creating UML sequence diagrams with lifelines and messages
- Working with classifiers (class, interface, enumeration, collaboration)
Covers:
- UML class diagram shapes ()
shape.type = 'UmlClassifier' - Classifier types: Class, Interface, Enumeration, Collaboration
- Attributes, operations, and members syntax
- UML relationship connector types
- UML sequence diagram ()
shape.type = 'UmlActivity' - Lifelines, messages, and fragments
📄 阅读:references/uml-diagrams.md
阅读时机:
- 构建包含属性和方法的UML类图
- 建模关系(关联、泛化、依赖)
- 创建包含生命线和消息的UML序列图
- 使用分类器(类、接口、枚举、协作)
涵盖内容:
- UML类图形状()
shape.type = 'UmlClassifier' - 分类器类型:类、接口、枚举、协作
- 属性、操作和成员语法
- UML关系连接器类型
- UML序列图()
shape.type = 'UmlActivity' - 生命线、消息和片段
Layouts
布局
📄 Read: references/layouts.md
When to read:
- Automatically arranging nodes in a tree, hierarchy, or radial pattern
- Creating org charts driven by parent-child data
- Building mind maps from data sources
- Configuring flowchart layouts with decision/process shapes
- Customizing layout spacing, orientation, and alignment
Covers:
- — top-down/left-right tree layouts
HierarchicalTree - — classic org chart with
OrganizationalChart/getNodeDefaultsgetConnectorDefaults - — branching mind map layout
MindMap - — circular radial layout
RadialTree - layout (automatic flow arrangement)
Flowchart - for multi-parent hierarchies
ComplexHierarchicalTree - property:
layout,type,orientation,margin,horizontalSpacingverticalSpacing - module
LayoutAnimation - Layout events
📄 阅读:references/layouts.md
阅读时机:
- 自动以树形、分层或放射状排列节点
- 由父子数据驱动创建组织结构图
- 从数据源构建思维导图
- 配置包含决策/流程形状的流程图布局
- 自定义布局间距、方向和对齐方式
涵盖内容:
- — 自上而下/自左向右的树形布局
HierarchicalTree - — 经典组织结构图,搭配
OrganizationalChart/getNodeDefaultsgetConnectorDefaults - — 分支式思维导图布局
MindMap - — 圆形放射状布局
RadialTree - 布局(自动流程排列)
Flowchart - :适用于多父级分层结构
ComplexHierarchicalTree - 属性:
layout、type、orientation、margin、horizontalSpacingverticalSpacing - 模块
LayoutAnimation - 布局事件
Swimlanes
泳道
📄 Read: references/swimlanes.md
When to read:
- Creating multi-lane process diagrams
- Adding phases to represent timeline or stages
- Configuring swimlane headers and orientation
- Placing child nodes inside lanes
- Using swimlane shapes from the symbol palette
Covers:
- Swimlane
shape.type = 'SwimLane' - Lanes and phases configuration
- Header text, size, and orientation
- Child nodes inside lanes
- Swimlane palette integration
- Swimlane interaction (add/remove lanes)
📄 阅读:references/swimlanes.md
阅读时机:
- 创建多泳道流程图表
- 添加阶段以表示时间线或步骤
- 配置泳道标题和方向
- 在泳道内放置子节点
- 使用符号面板中的泳道形状
涵盖内容:
- 泳道
shape.type = 'SwimLane' - 泳道和阶段配置
- 标题文本、大小和方向
- 泳道内的子节点
- 泳道面板集成
- 泳道交互(添加/删除泳道)
Groups and Containers
组与容器
📄 Read: references/groups-and-containers.md
When to read:
- Grouping multiple nodes for collective movement/selection
- Adding/removing children from groups at runtime
- Using container nodes to visually bound child nodes
- Configuring padding, fit-to-children behavior
Covers:
- Group node and
shape.type = 'Group'arraychildren - Grouping/ungrouping nodes via diagram methods
- Adding children at runtime
- Container node configuration
- Padding and auto-fit behavior for containers
📄 阅读:references/groups-and-containers.md
阅读时机:
- 对多个节点进行分组,实现集体移动/选择
- 在运行时向组中添加/移除子节点
- 使用容器节点可视化绑定子节点
- 配置内边距、自适应子节点行为
涵盖内容:
- 组节点和
shape.type = 'Group'数组children - 通过图表方法对节点进行分组/取消分组
- 在运行时添加子节点
- 容器节点配置
- 容器的内边距和自适应行为
Symbol Palette
符号面板
📄 Read: references/symbol-palette.md
When to read:
- Adding a drag-and-drop shape sidebar to your diagram app
- Defining custom symbol sets (palettes)
- Customizing palette icon size, search behavior, and accordion
- Handling /
symbolDragEntereventssymbolDrop
Covers:
- setup alongside
SymbolPaletteComponentDiagramComponent - Defining with symbol arrays
palettes - for display customization
getSymbolInfo - Palette accordion: expanding/collapsing groups
- Search functionality
- Symbol preview size configuration
- Palette events
📄 阅读:references/symbol-palette.md
阅读时机:
- 为图表应用添加可拖拽形状的侧边栏
- 定义自定义符号集(面板)
- 自定义面板图标大小、搜索行为和折叠面板
- 处理/
symbolDragEnter事件symbolDrop
涵盖内容:
- 与一起设置
DiagramComponentSymbolPaletteComponent - 使用符号数组定义
palettes - :自定义显示
getSymbolInfo - 面板折叠面板:展开/折叠组
- 搜索功能
- 符号预览大小配置
- 面板事件
Data Binding
数据绑定
📄 Read: references/data-binding.md
When to read:
- Generating diagrams automatically from JSON or remote data
- Mapping and
idfields for hierarchyparentId - Using for remote or filtered data
DataManager - Customizing node appearance based on data properties ()
setNodeTemplate - Connecting to a PostgreSQL or external data source
Covers:
- property
dataSourceSettings - ,
idfield mappingparentId - with local arrays or remote URLs
DataManager - and
getNodeDefaultsfor data-driven stylingsetNodeTemplate - PostgreSQL data source integration
- Rendering org charts from flat JSON data
📄 阅读:references/data-binding.md
阅读时机:
- 从JSON或远程数据源自动生成图表
- 映射和
id字段以实现分层结构parentId - 使用处理远程或过滤后的数据
DataManager - 根据数据属性自定义节点外观()
setNodeTemplate - 连接到PostgreSQL或外部数据源
涵盖内容:
- 属性
dataSourceSettings - 、
id字段映射parentId - :处理本地数组或远程URL
DataManager - 和
getNodeDefaults:实现数据驱动的样式setNodeTemplate - PostgreSQL数据源集成
- 从扁平JSON数据渲染组织结构图
Interaction and Tools
交互与工具
📄 Read: references/interaction-and-tools.md
When to read:
- Enabling/disabling node and connector interactions (drag, resize, select)
- Switching diagram tool modes (pointer, draw, pan)
- Configuring diagram constraints
- Adding custom keyboard commands or toolbar actions
- Implementing undo/redo
- Setting up context menus or user handles
Covers:
- ,
DiagramConstraints,NodeConstraintsConnectorConstraints - property:
tool,DiagramTools.Default,ZoomPanDrawOnce - Selection, drag, resize, rotate interactions
- for keyboard shortcuts
commands - Undo/Redo (module)
UndoRedo - Context menu (module)
DiagramContextMenu - User handles for custom action buttons on nodes
- module and snap settings
Snapping
📄 阅读:references/interaction-and-tools.md
阅读时机:
- 启用/禁用节点和连接器的交互(拖拽、调整大小、选择)
- 切换图表工具模式(指针、绘制、平移)
- 配置图表约束
- 添加自定义键盘命令或工具栏操作
- 实现撤销/重做
- 设置上下文菜单或用户操作手柄
涵盖内容:
- 、
DiagramConstraints、NodeConstraintsConnectorConstraints - 属性:
tool、DiagramTools.Default、ZoomPanDrawOnce - 选择、拖拽、调整大小、旋转交互
- :键盘快捷键
commands - 撤销/重做(模块)
UndoRedo - 上下文菜单(模块)
DiagramContextMenu - 用户操作手柄:节点上的自定义操作按钮
- 模块和对齐设置
Snapping
Serialization and Export
序列化与导出
📄 Read: references/serialization-and-export.md
When to read:
- Saving and restoring diagram state as JSON
- Exporting the diagram as PNG, JPEG, or SVG
- Printing diagram content
- Importing Visio (.vsdx) files
- Migrating from EJ1 diagram format
Covers:
- and
diagram.saveDiagram()diagram.loadDiagram(json) - module injection
PrintAndExport - Export settings: format, region, margin, background
- Print dialog and options
- Visio file import ()
visio.md - EJ1 serialization compatibility (module)
Ej1Serialization
📄 阅读:references/serialization-and-export.md
阅读时机:
- 将图表状态保存为JSON并恢复
- 将图表导出为PNG、JPEG或SVG
- 打印图表内容
- 导入Visio(.vsdx)文件
- 从EJ1图表格式迁移
涵盖内容:
- 和
diagram.saveDiagram()diagram.loadDiagram(json) - 模块注入
PrintAndExport - 导出设置:格式、区域、边距、背景
- 打印对话框和选项
- Visio文件导入()
visio.md - EJ1序列化兼容性(模块)
Ej1Serialization
Diagram Settings
图表设置
📄 Read: references/diagram-settings.md
When to read:
- Managing diagram layers (visibility, locking, ordering)
- Enabling virtualization for performance with large diagrams
- Configuring grid lines, snapping, and rulers
- Setting page size, orientation, and margins
- Configuring scroll behavior and limits
- Adding tooltips to diagram elements
- Using the Overview component for minimap navigation
- Enabling localization or RTL support
- Understanding accessibility features
Covers:
- Layers: add, lock, set visibility, active layer
- module for large diagrams
Virtualization - Grid lines: dots, lines, snap settings
- Ruler configuration
- :
scrollSettings,scrollLimit,minZoommaxZoom - : size, orientation, background, multiplePage
pageSettings - Tooltip on nodes and connectors
- minimap setup
OverviewComponent - Localization and RTL
- ARIA and keyboard accessibility
📄 阅读:references/diagram-settings.md
阅读时机:
- 管理图表图层(可见性、锁定、排序)
- 启用虚拟化以提升大型图表的性能
- 配置网格线、对齐和标尺
- 设置页面大小、方向和边距
- 配置滚动行为和限制
- 为图表元素添加工具提示
- 使用Overview组件实现小地图导航
- 启用本地化或RTL支持
- 理解可访问性功能
涵盖内容:
- 图层:添加、锁定、设置可见性、活动图层
- 模块:适用于大型图表
Virtualization - 网格线:点、线、对齐设置
- 标尺配置
- :
scrollSettings、scrollLimit、minZoommaxZoom - :大小、方向、背景、多页
pageSettings - 节点和连接器的工具提示
- 小地图设置
OverviewComponent - 本地化和RTL
- ARIA和键盘可访问性
Quick Start Example
快速入门示例
Minimal Flowchart
最小化流程图
tsx
import { DiagramComponent, NodeModel, ConnectorModel, Inject, UndoRedo } from '@syncfusion/ej2-react-diagrams';
const nodes: NodeModel[] = [
{ id: 'start', offsetX: 300, offsetY: 80, width: 140, height: 50,
shape: { type: 'Flow', shape: 'Terminator' }, annotations: [{ content: 'Start' }] },
{ id: 'process', offsetX: 300, offsetY: 180, width: 140, height: 50,
shape: { type: 'Flow', shape: 'Process' }, annotations: [{ content: 'Process' }] },
{ id: 'end', offsetX: 300, offsetY: 290, width: 140, height: 50,
shape: { type: 'Flow', shape: 'Terminator' }, annotations: [{ content: 'End' }] },
];
const connectors: ConnectorModel[] = [
{ id: 'c1', sourceID: 'start', targetID: 'process' },
{ id: 'c2', sourceID: 'process', targetID: 'end' },
];
export default function App() {
return (
<DiagramComponent id="diagram" width={'100%'} height={'500px'}
nodes={nodes} connectors={connectors}
getConnectorDefaults={(obj) => { obj.type = 'Orthogonal'; return obj; }}>
<Inject services={[UndoRedo]} />
</DiagramComponent>
);
}CSS import: and peer CSS for , , , .
@import '@syncfusion/ej2-react-diagrams/styles/material.css';ej2-baseej2-popupsej2-splitbuttonsej2-navigationstsx
import { DiagramComponent, NodeModel, ConnectorModel, Inject, UndoRedo } from '@syncfusion/ej2-react-diagrams';
const nodes: NodeModel[] = [
{ id: 'start', offsetX: 300, offsetY: 80, width: 140, height: 50,
shape: { type: 'Flow', shape: 'Terminator' }, annotations: [{ content: 'Start' }] },
{ id: 'process', offsetX: 300, offsetY: 180, width: 140, height: 50,
shape: { type: 'Flow', shape: 'Process' }, annotations: [{ content: 'Process' }] },
{ id: 'end', offsetX: 300, offsetY: 290, width: 140, height: 50,
shape: { type: 'Flow', shape: 'Terminator' }, annotations: [{ content: 'End' }] },
];
const connectors: ConnectorModel[] = [
{ id: 'c1', sourceID: 'start', targetID: 'process' },
{ id: 'c2', sourceID: 'process', targetID: 'end' },
];
export default function App() {
return (
<DiagramComponent id="diagram" width={'100%'} height={'500px'}
nodes={nodes} connectors={connectors}
getConnectorDefaults={(obj) => { obj.type = 'Orthogonal'; return obj; }}>
<Inject services={[UndoRedo]} />
</DiagramComponent>
);
}CSS导入: 以及 、、、的依赖CSS。
@import '@syncfusion/ej2-react-diagrams/styles/material.css';ej2-baseej2-popupsej2-splitbuttonsej2-navigationsCommon Patterns
常见模式
Pattern 1: Org Chart from Data Source
—
tsx
import { DiagramComponent, HierarchicalTree, DataBinding, Inject } from '@syncfusion/ej2-react-diagrams';
import { DataManager } from '@syncfusion/ej2-data';
const data = [
{ Name: 'CEO' },
{ Name: 'CTO', ReportingPerson: 'CEO' },
{ Name: 'Dev Lead', ReportingPerson: 'CTO' },
];
export default function App() {
return (
<DiagramComponent id="diagram" width={'100%'} height={'500px'}
dataSourceSettings={{ id: 'Name', parentId: 'ReportingPerson', dataManager: new DataManager(data) }}
layout={{ type: 'OrganizationalChart' }}
getNodeDefaults={(node) => { node.width = 120; node.height = 40; return node; }}
getConnectorDefaults={(obj) => { obj.type = 'Orthogonal'; return obj; }}>
<Inject services={[DataBinding, HierarchicalTree]} />
</DiagramComponent>
);
}###模式1:从数据源生成组织结构图
tsx
import { DiagramComponent, HierarchicalTree, DataBinding, Inject } from '@syncfusion/ej2-react-diagrams';
import { DataManager } from '@syncfusion/ej2-data';
const data = [
{ Name: 'CEO' },
{ Name: 'CTO', ReportingPerson: 'CEO' },
{ Name: 'Dev Lead', ReportingPerson: 'CTO' },
];
export default function App() {
return (
<DiagramComponent id="diagram" width={'100%'} height={'500px'}
dataSourceSettings={{ id: 'Name', parentId: 'ReportingPerson', dataManager: new DataManager(data) }}
layout={{ type: 'OrganizationalChart' }}
getNodeDefaults={(node) => { node.width = 120; node.height = 40; return node; }}
getConnectorDefaults={(obj) => { obj.type = 'Orthogonal'; return obj; }}>
<Inject services={[DataBinding, HierarchicalTree]} />
</DiagramComponent>
);
}###模式2:保存与加载图表状态
使用序列化为JSON字符串;使用恢复状态。注入以支持历史记录功能。完整示例请查看references/serialization-and-export.md。
diagramInstance.saveDiagram()diagramInstance.loadDiagram(json)UndoRedo###模式3:带符号面板的图表
在旁边渲染。使用形状数组定义面板,设置/,用户即可将形状拖拽到画布上。完整示例请查看references/symbol-palette.md。
DiagramComponentSymbolPaletteComponentsymbolHeightsymbolWidthPattern 2: Save and Load Diagram State
模块注入参考
Use to serialize to JSON string; to restore. Inject for history support. For full examples see references/serialization-and-export.md.
diagramInstance.saveDiagram()diagramInstance.loadDiagram(json)UndoRedo仅注入图表所需的模块:
<Inject services={[HierarchicalTree, DataBinding, UndoRedo]} />| 模块 | 用途 |
|---|---|
| 树形和组织结构图布局 |
| 思维导图布局 |
| 放射状/圆形布局 |
| 多父级分层结构 |
| 数据源集成 |
| 撤销/重做历史记录 |
| 网格对齐 |
| 导出与打印 |
| BPMN形状 |
| 动画布局 |
| 右键上下文菜单 |
| 连接器交叉桥接 |
| 编辑连接器段 |
| 加载EJ1图表JSON |
Pattern 3: Diagram with Symbol Palette
关键属性
Render alongside . Define palettes with shape arrays, set /, and users can drag shapes onto the canvas. For full examples see references/symbol-palette.md.
SymbolPaletteComponentDiagramComponentsymbolHeightsymbolWidth| 属性 | 类型 | 描述 |
|---|---|---|
| | 节点定义数组 |
| | 连接器定义数组 |
| | 自动布局配置 |
| | 自动生成图表的数据源设置 |
| | 所有节点的默认属性 |
| | 所有连接器的默认属性 |
| | 节点的自定义模板渲染 |
| | 活动交互工具模式 |
| | 网格与对齐配置 |
| | 滚动限制与缩放范围 |
| | 页面大小、方向、背景 |
| | 启用/禁用图表级交互 |
| | 图表画布宽度(例如: |
| | 图表画布高度(例如: |
Module Injection Reference
相关组件
Inject only the modules your diagram uses:
<Inject services={[HierarchicalTree, DataBinding, UndoRedo]} />| Module | Purpose |
|---|---|
| Tree and org chart layouts |
| Mind map layout |
| Radial/circular layout |
| Multi-parent hierarchies |
| Data source integration |
| Undo/redo history |
| Grid snapping |
| Export & print |
| BPMN shapes |
| Animated layouts |
| Right-click context menu |
| Bridge overlapping connectors |
| Edit connector segments |
| Load EJ1 diagram JSON |
- 图表 - 数据驱动的图表和图形
- 看板 - 看板可视化
- 数据网格 - 表格数据展示
Key Props
—
| Prop | Type | Description |
|---|---|---|
| | Array of node definitions |
| | Array of connector definitions |
| | Automatic layout configuration |
| | Data source for auto-generated diagrams |
| | Default properties for all nodes |
| | Default properties for all connectors |
| | Custom template rendering for nodes |
| | Active interaction tool mode |
| | Grid and snap configuration |
| | Scroll limits and zoom bounds |
| | Page size, orientation, background |
| | Enable/disable diagram-level interactions |
| | Diagram canvas width (e.g., |
| | Diagram canvas height (e.g., |
—
Related Components
—
- Chart - Data-driven charts and graphs
- Kanban - Kanban board visualization
- Data Grid - Tabular data display
—