installation
sudo apt install Graphviz graphviz-doc
Drawing
The Graphviz contains 3 elements, graphs, vertices, and edges. Each element can have its own attributes that define the font, style, color, shape, and so on. Here are some simple examples to help us quickly understand the basic usage of Graphviz. The first picture of Graphviz
Create a new file, people named Try.dot, the contents of the document are as follows:
digraph G {
main-> parse-> execute;
Main-> init;
Main-> cleanup;
Execute-> make_string;
Execute-> printf
init-> make_string;
Main-> printf;
Execute-> compare;
}
Enter the following command in the terminal:
Dot-tpng Try.dot-o Try.png
A picture, named Try.png, is generated, as shown in the image below.
Supported picture formats
See the official website, almost all format pictures can be generated. The command to generate a picture in XX format is:
Dot-txx Filename-o output_filename.xx
Chinese Display
Need to complete the following two points at the same time: 1. Modify node and Edge FontName attributes to Fangsong, or other installed Chinese fonts (SimSun, etc.); 2. The file is set to UTF8 encoding.
For example, the following code
digraph dataaccesslayer {
node[fontname= "Fangsong"];
Edge[fontname= "Fangsong"];
input [shape=box,label= "Enter text"];
semanticparsenetwork [shape=box,label= "Semantic engine network"];
Input-> semanticparsenetwork;
}
Generate the following picture: