\n
换行符//
或/* */
digraph
, 节点关系: 指向->
graph
, 节点关系: 连通 --
node[attribute1=value1, attribute2=value2]
构造边
关系 | 有向图 | 无向图 |
---|---|---|
一对一 | a->b; | a–b; |
一对多 | a->{b;c;d}; | a–{b;c;d}; |
多对一 | {b;c;d}->a; | {b;c;d}–a; |
多对多 | {m,n,p,q}->{b;c;d}; | {m,n,p,q}->{b;c;d}; |
官方文档:http://www.graphviz.org/documentation/
属性设置:https://graphviz.gitlab.io/_pages/doc/info/attrs.html
节点形状:https://graphviz.gitlab.io/_pages/doc/info/shapes.html
箭头形状:https://graphviz.gitlab.io/_pages/doc/info/arrows.html
颜色配置:https://graphviz.gitlab.io/_pages/doc/info/colors.html
digraph G {
A -> B;
A -> C -> B;
A -> D -> B;
}
digraph G {
size = "4, 4";
main [shape=box]; /* 这是注释 */
main -> parse [weight=8];
parse -> execute;
main -> init [style=dotted];
main -> cleanup;
execute -> { make_string; printf}
init -> make_string;
edge [color=red]; // 设置生效
main -> printf [style=bold,label="100 times"];
make_string [label="make a\n字符串"];
node [shape=box,style=filled,color=".7 .3 1.0"];
execute -> compare;
}
digraph G {
a -> b -> c;
b -> d;
a [shape=polygon,sides=5,peripheries=3,color=lightblue,style=filled];
c [shape=polygon,sides=4,skew=.4,label="hello world"]
d [shape=invtriangle];
e [shape=polygon,sides=4,distortion=.7];
}
digraph html {
abc [shape=none, margin=0, label=<
<TABLE BORDER="0" CELLBORDER="1" CELLSPACING="0" CELLPADDING="4">
<TR>
<TD ROWSPAN="3"><FONT COLOR="red">helloFONT><BR/>worldTD>
<TD COLSPAN="3">bTD>
<TD ROWSPAN="3" BGCOLOR="lightgrey">gTD>
<TD ROWSPAN="3">hTD>
TR>
<TR>
<TD>cTD>
<TD PORT="here">dTD>
<TD>eTD>
TR>
<TR>
<TD COLSPAN="3">fTD>
TR>
TABLE>>];
}
digraph g {
node [shape = record,height=.1];
node0[label = " | G| " ];
node1[label = " | E| " ];
node2[label = " | B| " ];
node3[label = " | F| " ];
node4[label = " | R| " ];
node5[label = " | H| " ];
node6[label = " | Y| " ];
node7[label = " | A| " ];
node8[label = " | C| " ];
"node0":f2 -> "node4":f1;
"node0":f0 -> "node1":f1;
"node1":f0 -> "node2":f1;
"node1":f2 -> "node3":f1;
"node2":f2 -> "node8":f1;
"node2":f0 -> "node7":f1;
"node4":f2 -> "node6":f1;
"node4":f0 -> "node5":f1;
}
//定义节点属性
digraph g {
//==========定义节点关系============
a->b;
b->c;
c->a;
c->d->e->f;
d->g;
e->h;
//==========定义节点属性============
//定义a节点为长方形, 样式为填充, 填充颜色为#ABACBA
a[shape=box,label="Server1\nWebServer",fillcolor="#ABACBA",style=filled];
//定义b为5边形, 标签为"bb", 样式为填充, 填充色为red
b[shape=polygon,sides=5,label="bb",style=filled,fillcolor=red];
//c, 默认为椭圆
d[shape=circle]; //园
e[shape=triangle]; //三角形
f[shape=polygon, sides=4, skew=0.5]; //平行四边形
g[shape=polygon, distortion=0.5]; //梯形, 上边长
h[shape=polygon, distortion=-.5]; //梯形, 下边长
}
有向图
digraph g {
//edge[style=dashed]; //定义边的样式, 虚线
node[peripheries=2, style=filled, color="#eecc80"];
a->b [color=red, style=dashed]; //定义边的颜色, 红色 (b和方括号之间必须有空格)
b->c; //箭头, 三角形; 箭尾, 菱形
b->d [arrowhead=box]; //箭头, 长方形
b->e [dir=none]; //没有箭头
d->f [dir=both]; //双向箭头
f->h [label=go]; //定义edge的标签
f->k [arrowhead=diamond]; //更改箭头形状
k->y [headlabel="哈哈", taillabel="洗洗"];
}
// (更多箭头形状请参考官方文档: http://www.graphviz.org/content/arrow-shapes)
无向图
graph g {
edge[style=dashed]; //定义边的样式, 虚线
a -- b [color=red]; //定义边的颜色, 红色 (b和方括号之间必须有空格)
}
参考:
- 官网文档:https://graphviz.gitlab.io/_pages/pdf/dotguide.pdf
- graphviz dot语言学习笔记
- dot语法