graphviz
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGraphviz DOT Diagram Generator
Graphviz DOT 图表生成器
Important: Useas the code fence identifier, NOT```dot.```graphviz
Quick Start: Choose (directed) or (undirected) → Define nodes with attributes (shape, color, label) → Connect with or → Set layout (rankdir, spacing) → Wrap in fence. Default: top-to-bottom (), cluster names must start with , use semicolons.
digraphgraph->--```dotrankdir=TBcluster_重要提示: 请使用作为代码块标识,而非```dot。```graphviz
快速入门: 选择(有向图)或(无向图)→ 定义带属性的节点(形状、颜色、标签)→ 使用或连接节点→ 设置布局(rankdir、间距)→ 包裹在代码块中。默认设置:从上到下布局(),集群名称必须以开头,语句以分号结尾。
digraphgraph->--```dotrankdir=TBcluster_Critical Syntax Rules
关键语法规则
Rule 1: Cluster Naming
规则1:集群命名
❌ subgraph backend { } → Won't render as box
✅ subgraph cluster_backend { } → Must start with cluster_❌ subgraph backend { } → 无法渲染为方框
✅ subgraph cluster_backend { } → 必须以cluster_开头Rule 2: Node IDs with Spaces
规则2:含空格的节点ID
❌ API Gateway [label="API"]; → Invalid ID
✅ "API Gateway" [label="API"]; → Quote the ID
✅ api_gateway [label="API Gateway"]; → Use underscore ID❌ API Gateway [label="API"]; → 无效ID
✅ "API Gateway" [label="API"]; → 为ID添加引号
✅ api_gateway [label="API Gateway"]; → 使用下划线作为IDRule 3: Edge Syntax Difference
规则3:边的语法差异
digraph: A -> B; → Directed arrow
graph: A -- B; → Undirected linedigraph: A -> B; → 有向箭头
graph: A -- B; → 无向直线Rule 4: Attribute Syntax
规则4:属性语法
❌ node [shape=box color=red] → Missing comma
✅ node [shape=box, color=red]; → Comma separated❌ node [shape=box color=red] → 缺少逗号
✅ node [shape=box, color=red]; → 使用逗号分隔属性Rule 5: HTML Labels
规则5:HTML标签
✅ shape=plaintext for HTML labels
✅ Use < > not " " for HTML content✅ 为HTML标签设置shape=plaintext
✅ HTML内容使用< >而非" "包裹Common Pitfalls
常见问题
| Issue | Solution |
|---|---|
| Nodes overlapping | Increase |
| Poor layout | Change |
| Edges crossing | Use |
| Cluster not showing | Name must start with |
| Label not displaying | Check quote escaping |
| 问题 | 解决方案 |
|---|---|
| 节点重叠 | 增大 |
| 布局效果差 | 修改 |
| 边交叉 | 使用 |
| 集群未显示 | 名称必须以 |
| 标签未显示 | 检查引号转义是否正确 |
Output Format
输出格式
markdown
```dot
digraph G {
[diagram code]
}
```markdown
```dot
digraph G {
[图表代码]
}
```Related Files
相关文档
For advanced layout control and complex styling, refer to references below:
- syntax.md — Layout control (rankdir, splines, rank), HTML labels, edge styles, cluster subgraphs, and record-based nodes
如需高级布局控制和复杂样式设置,请参考以下文档:
- syntax.md — 布局控制(rankdir、splines、rank)、HTML标签、边样式、集群子图以及基于记录的节点