How to create diagrams and charts in Markdown?

How to create diagrams and charts in Markdown?

Mermaid lets you create diagrams and visualizations using text and code.


Flowchart

Node shapes

Simple node
node
flowchart LR
node
Square node
square node
flowchart LR
square[square node]
Round node
round node
flowchart LR
round(round node)
Pill node
pill node
flowchart LR
stadium([pill node])
Subroutine node
subroutine node
flowchart LR
subroutine[[subroutine node]]
Cylindrical node
cylindrical node
flowchart LR
cylindrical[(cylindrical node)]
Circular node
circular node
flowchart LR
circular((circular node))
Asymmetric node
asymmetric node
flowchart LR
asymmetric>asymmetric node]
Rhombus node
rhombus node
flowchart LR
rhombus{rhombus node}
Hexagon node
hexagon node
flowchart LR
hexagon{{hexagon node}}
Right parallelogram node
right parallelogram node
flowchart LR
parallelogram_right[/right parallelogram node/]
Left parallelogram node
left parallelogram node
flowchart LR
parallelogram_left[\left parallelogram node\]
Down trapezoid node
down trapezoid node
flowchart LR
trapezoid_down[/down trapezoid node\]
Up trapezoid node
up trapezoid node
flowchart LR
trapezoid_up[\up trapezoid node/]
Double circular node
Syntax error in graph
flowchart LR
double_circular(((double circular node)))

Node Connections

A
B
flowchart LR
A --- B
A
B
flowchart LR
A -.- B
A
B
flowchart LR
A === B
With description
Pipe syntax
description
A
B
flowchart LR
A --->|description| B
Between syntax
description
A
B
flowchart LR
A --description-> B
Arrow heads
Default arrow
A
B
flowchart LR
A --> B
Start arrow
A
B
flowchart LR
A --o B
Close arrow
A
B
flowchart LR
A --x B
Multi directional arrows
A
B
C
D
E
F
flowchart LR
A <--> B
C o--o D
E x--x F

Subgraphs

two
D
C
Label
B
A
flowchart TB
subgraph one[Label]
A --> B
end
subgraph two
C --> D
end
one --> two

Interactions

A
B
C
D
flowchart LR
A-->B
B-->C
C-->D
click A href "http://localhost:3000"
click B href "https://www.github.com"

Sequence

Syntax

Participants
AliceBobHi BobHi AliceAliceBob
sequenceDiagram
participant Alice
participant Bob
Alice->>Bob: Hi Bob
Bob->>Alice: Hi Alice
Actors
AliceBobHi BobHi AliceAliceBob
sequenceDiagram
actor Alice
actor Bob
Alice->>Bob: Hi Bob
Bob->>Alice: Hi Alice
Aliases
AliceJohnHello John, how are you?Great!AliceJohn
sequenceDiagram
participant A as Alice
participant J as John
A->>J: Hello John, how are you?
J->>A: Great!

Arrows

ABSolid line without arrowDotted line without arrowSolid line with arrowheadDotted line with arrowheadSolid line with a cross at the endDotted line with a cross at the endSolid line with an open arrow at the end (async)Dotted line with a open arrow at the end (async)AB
sequenceDiagram
A->B: Solid line without arrow
A-->B: Dotted line without arrow
A->>B: Solid line with arrowhead
A-->>B: Dotted line with arrowhead
A-xB: Solid line with a cross at the end
A--xB: Dotted line with a cross at the end
A-)B: Solid line with an open arrow at the end (async)
A--)B: Dotted line with a open arrow at the end (async)

Activations

ABactivate B+ A- Bdeactivate AAB
sequenceDiagram
A->>B: B
activate B
B->>+A: B
B->>-A: B
A->>B: B
deactivate A

Class

Syntax

BankAccount
string owner
number balance
deposit(amount)
withdrawal(amount)
classDiagram
class BankAccount
BankAccount : string owner
BankAccount : number balance
BankAccount : deposit(amount)
BankAccount : withdrawal(amount)

Visibility

Visibility
+string public
-string private
#string protected
~string internal
string static
getStatic()
getAbstract()
classDiagram
class Visibility
Visibility: +string public
Visibility: -string private
Visibility: #string protected
Visibility: ~string internal
Visibility: string static$
Visibility: getStatic()$
Visibility: getAbstract()*

Relationships

Inheritance
Composition
Aggregation
Association
Link(Solid)
Dependency
Realization
Link(Dashed)
classA
classB
classC
classD
classE
classF
classG
classH
classI
classJ
classK
classL
classM
classN
classO
classP
classDiagram
classA --|> classB : Inheritance
classC --* classD : Composition
classE --o classF : Aggregation
classG --> classH : Association
classI -- classJ : Link(Solid)
classK ..> classL : Dependency
classM ..|> classN : Realization
classO .. classP : Link(Dashed)

Cardinality / Multiplicity on relations

1
*
1
1..*
Contains
many
Customer
Ticket
Student
Course
Galaxy
Star
classDiagram
Customer "1" --> "*" Ticket
Student "1" --> "1..*" Course
Galaxy --> "many" Star : Contains

State

Syntax

transition
stateNode
stateDiagram-v2
direction LR
[*] --> stateNode: transition
stateNode --> [*]

Composite

transition
mainState
subState
subSubState
stateDiagram-v2
direction LR
[*] --> mainState: transition
state mainState {
direction LR
[*] --> subState
state subState {
direction LR
[*] --> subSubState
subSubState --> [*]
}
subState --> [*]
}
mainState --> [*]

Choice

condition
false
true
stateDiagram-v2
state choice <<choice>>
[*] --> condition
condition --> choice
choice --> false
choice --> true

Forks

A
B
stateDiagram-v2
state fork <<fork>>
state join <<join>>
[*] --> fork
fork --> A
fork --> B
A --> join
B --> join
join --> [*]

Notes

The state with a note
Important information! You can write
notes.
State2
This is the note to the left.
stateDiagram-v2
State1: The state with a note
note right of State1
Important information! You can write
notes.
end note
State1 --> State2
note left of State2 : This is the note to the left.

Concurrency

concurrency
transition
stateNode1
transition
stateNode2
stateDiagram-v2
direction LR
[*] --> concurrency
state concurrency {
direction TB
[*] --> stateNode1: transition
stateNode1 --> [*]
--
direction TB
[*] --> stateNode2: transition
stateNode2 --> [*]
}
concurrency --> [*]

Entity Relationship

Syntax

CARNAMED-DRIVERPERSONallowsis
erDiagram
CAR ||--o{ NAMED-DRIVER : allows
PERSON ||--o{ NAMED-DRIVER : is

Relationships

One
oneto-onerelationship
erDiagram
one ||--|| to-one : relationship
Zero or one
zero-oneto-zero-onerelationship
erDiagram
zero-one |o--o| to-zero-one : relationship
Zero or more
zero-moreto-zero-morerelationship
erDiagram
zero-more }o--o{ to-zero-more : relationship
One or more
one-moreto-one-morerelationship
erDiagram
one-more }|--|{ to-one-more : relationship

Attributes

CARstringregistrationNumberstringmakestringmodelNAMED-DRIVERPERSONstringfirstNamestringlastNameintageallowsis
erDiagram
CAR ||--o{ NAMED-DRIVER : allows
CAR {
string registrationNumber
string make
string model
}
PERSON ||--o{ NAMED-DRIVER : is
PERSON {
string firstName
string lastName
int age
}

User Journey

CatMe
Go to work
Go to work
Me
Make tea
Make tea
Me
Go upstairs
Go upstairs
MeCat
Do work
Do work
Go home
Go home
Me
Go downstairs
Go downstairs
Me
Sit down
Sit down
My working day
journey
title My working day
section Go to work
Make tea: 5: Me
Go upstairs: 3: Me
Do work: 1: Me, Cat
section Go home
Go downstairs: 5: Me
Sit down: 5: Me

Gantt

Syntax

2022-11-012022-12-012023-01-012023-02-012023-03-012023-04-012023-05-012023-06-012023-07-012023-08-012023-09-012023-10-012023-11-012023-12-01default critical active critical active milestone milestone
gantt
default :a, 2022-10-08, 1w
critical :crit, b, 2022-10-08, 1d
active :active, c, after b a, 1d
critical active :crit, active, ca, after c, 1d
milestone : milestone, m1, 17:49, 2min
milestone : milestone, m2, 18:14, 1d

Pie chart

40%46%9%5%Key elements in Product XCalcium [42.96]Potassium [50.05]Magnesium [10.01]Iron [5]
pie showData
title Key elements in Product X
"Calcium" : 42.96
"Potassium" : 50.05
"Magnesium" : 10.01
"Iron" : 5

Requirement

Syntax

<<Requirement>>test_reqId: 1Text: the test text.Risk: HighVerification: Test<<Element>>test_entityType: simulationDoc Ref: None<<satisfies>>
requirementDiagram
requirement test_req {
id: 1
text: the test text.
risk: high
verifymethod: test
}
element test_entity {
type: simulation
}
test_entity - satisfies -> test_req

Requirement

<<Requirement>>test_reqId: 1Text: the test text.Risk: HighVerification: Test
requirementDiagram
requirement test_req {
id: 1
text: the test text.
risk: high
verifymethod: test
}

Types:

  • requirement
  • functionalRequirement
  • interfaceRequirement
  • performanceRequirement
  • physicalRequirement
  • designConstraint

Risk:

  • Low
  • Medium
  • High

Verification Method:

  • Analysis
  • Inspection
  • Test
  • Demonstration

Gitgraph

%%{ init: { 'logLevel': 'debug', 'theme': 'dark' } }%%
gitGraph
commit id: "initial commit"
branch hom
branch feat/button
checkout feat/button
commit id: "create button"
commit id: "finish button"
checkout hom
merge feat/button
checkout feat/button
commit id: "fix hover"
checkout hom
merge feat/button
checkout feat/button
commit id: "fix accessibility"
checkout hom
merge feat/button
checkout main
merge hom