メインコンテンツへスキップ

Mermaid フローチャートの書き方・早見表

フローチャートは処理と判断をつなぎます。担当を分けるにはサブグラフ、システム間のメッセージ順が中心ならシーケンス図を使います。

Mermaidフローチャートエディターで作成 →

クイックスタート

固定のidと引用符付きのラベルを使い、辺はid同士をつなぎます。

Mermaid
flowchart LR
  D["手引きの下書き"] --> R{"承認済み?"}
  R -->|はい| P["手引きを公開"]
  R -->|いいえ| D

読み込み中…

構文リファレンス

構文リファレンス
構文意味
flowchart / graph / LR / RL / TB / TD / BT図と方向を宣言します。TDとTBは同じです。
A[Text] / A(Text) / A([Text]) / A[[Text]] / A[(Text)]従来記法の長方形、角丸、スタジアム、サブルーチン、円柱です。
A((Text)) / A{Text} / A{{Text}} / A>Text] / A(((Text)))円、ひし形、六角形、非対称形、二重円です。
A[/Text/] / A[\Text\] / A[/Text\] / A[\Text/]左右の平行四辺形と台形です。
A@{ shape: rect, label: "Text" }カタログの標準名または別名を指定します。
--> / --- / -.-> / -.- / ==> / === / ~~~矢印、通常線、破線、太線、非表示の辺です。
<--> / o--o / x--x / --o / --x双方向、円、交差印の終端です。
A -->|Label| B / A -- Label --> B / A ----> Bラベルや追加のハイフンで最小の階層間隔を増やします。ピクセルは固定しません。
subgraph id [Label] / direction TB / endノードをまとめます。外部の接続は内部方向を上書きする場合があります。
classDef / class A,B name / A:::name再利用するスタイルを定義して適用します。
style A / linkStyle 0 / e1@--> / class e1 nameノード、0始まりの辺番号、辺のidにスタイルを付けます。id付きの辺はアニメーションも設定できます。
click A href "URL" / click A callback "Tooltip"クリックは表示環境に依存し、厳格モードでは無効です。
A["`**Bold** and *italic*`"]Markdown文字列で強調と自動折り返しを使えます。
A@{ icon: "fa:user", form: "square", pos: "t", h: 60 }アイコンはパックの登録が必要です。四角、円、角丸を選べます。
A@{ img: "/favicon.svg", label: "Text", w: 60, h: 60, constraint: "on" }画像は取得可能なURLが必要で、寸法や縦横比を指定できます。
config.layout: elk / config.flowchart.defaultRenderer: elkELKは追加のレイアウトで、表示環境での導入と登録が必要です。
%% / accTitle: / accDescr:コメントとアクセシビリティ用の説明です。
@{ shape: rect } / proc / process / rectangle処理
@{ shape: rounded } / eventイベント
@{ shape: stadium } / terminal / pill終端
@{ shape: fr-rect } / subprocess / subproc / framed-rectangle / subroutineサブプロセス
@{ shape: cyl } / db / database / cylinderデータベース
@{ shape: datastore } / data-storeデータストア
@{ shape: circle } / circ開始
@{ shape: bang } / bang爆発形
@{ shape: cloud } / cloudクラウド
@{ shape: diam } / decision / diamond / question判断
@{ shape: hex } / hexagon / prepare条件の準備
@{ shape: lean-r } / lean-right / in-outデータ入出力
@{ shape: lean-l } / lean-left / out-inデータ入出力
@{ shape: trap-b } / priority / trapezoid-bottom / trapezoid優先処理
@{ shape: trap-t } / manual / trapezoid-top / inv-trapezoid手作業
@{ shape: dbl-circ } / double-circle終了
@{ shape: text }テキスト
@{ shape: notch-rect } / card / notched-rectangleカード
@{ shape: lin-rect } / lined-rectangle / lined-process / lin-proc / shaded-process斜線付き処理
@{ shape: sm-circ } / start / small-circle開始
@{ shape: fr-circ } / stop / framed-circle終了
@{ shape: fork } / join分岐・結合
@{ shape: hourglass } / hourglass / collate照合
@{ shape: brace } / comment / brace-l注釈
@{ shape: brace-r }右側の注釈
@{ shape: braces }両側の括弧付き注釈
@{ shape: bolt } / com-link / lightning-bolt通信リンク
@{ shape: doc } / doc / document文書
@{ shape: delay } / half-rounded-rectangle遅延
@{ shape: h-cyl } / das / horizontal-cylinder直接アクセス記憶
@{ shape: lin-cyl } / disk / lined-cylinderディスク記憶
@{ shape: curv-trap } / curved-trapezoid / display表示
@{ shape: div-rect } / div-proc / divided-rectangle / divided-process分割処理
@{ shape: tri } / extract / triangle抽出
@{ shape: win-pane } / internal-storage / window-pane内部記憶
@{ shape: f-circ } / junction / filled-circle接合点
@{ shape: notch-pent } / loop-limit / notched-pentagonループ上限
@{ shape: flip-tri } / manual-file / flipped-triangle手動ファイル
@{ shape: sl-rect } / manual-input / sloped-rectangle手動入力
@{ shape: docs } / documents / st-doc / stacked-document複数文書
@{ shape: st-rect } / procs / processes / stacked-rectangle複数処理
@{ shape: bow-rect } / stored-data / bow-tie-rectangle保存データ
@{ shape: cross-circ } / summary / crossed-circle要約
@{ shape: tag-doc } / tag-doc / tagged-documentタグ付き文書
@{ shape: tag-rect } / tagged-rectangle / tag-proc / tagged-processタグ付き処理
@{ shape: flag } / paper-tape紙テープ
@{ shape: odd }非対称形
@{ shape: lin-doc } / lined-document線付き文書

図形とラベル

カタログは11.15の標準図形48種類と別名を網羅します。新しい図形には@{ shape: ... }を使い、従来の括弧記法も利用できます。

Mermaid
flowchart TB
  A@{ shape: sl-rect, label: "タイトルを入力" }
  B@{ shape: doc, label: "文書の下書き" }
  C@{ shape: diam, label: "完了?" }
  D@{ shape: cyl, label: "保管先" }
  A --> B --> C
  C -->|はい| D
  C -->|いいえ| A

読み込み中…

サブグラフ

内部ノードと外部ノードをつなぐと内部方向が失われる場合があります。方向を保ちたい場合はサブグラフ全体をつなぎます。

Mermaid
flowchart LR
  subgraph prep ["準備"]
    direction TB
    A["構成"] --> B["下書き"]
  end
  subgraph review ["レビュー"]
    direction TB
    C["確認"] --> D["承認"]
  end
  prep --> review

読み込み中…

スタイルとMarkdown

classDefで定義し、classや:::で適用します。styleは単一ノード、linkStyleは宣言順の番号、idは特定の辺を指定します。

Mermaid
flowchart LR
  A["`**手引き**の下書き`"]:::focus e1@--> B["レビュー"]
  B --> C["公開する"]
  classDef focus fill:#d3e5ff,stroke:#0070f3,color:#171717
  class B focus
  style C stroke-width:2px
  linkStyle 1 stroke:#0070f3,stroke-width:2px
  classDef edge stroke:#0070f3
  class e1 edge

読み込み中…

間隔とレイアウトの選択

nodeSpacingとrankSpacingで間隔を調整します。ELKやアイコンパックは環境側の登録が必要で、通常の図形には拡張は不要です。

Mermaid
---
config:
  flowchart:
    nodeSpacing: 35
    rankSpacing: 60
---
flowchart LR
  A["書く"] --> B["レビュー"] --> C["公開する"]

読み込み中…

よくある間違い

図形の括弧を閉じ忘れる

括弧を閉じ、ラベルを引用符で囲みます。

誤った構文(下に修正例があります)

flowchart LR
  A[Draft

endをidにする

endはサブグラフを閉じます。別のidを使い、表示名なら引用符で囲みます。

厳格モードでクリックを期待する

このサイトはコールバックを無効にしています。エディターへの外部リンクを使ってください。

制約

  • 正確な位置は自動配置が決め、ハイフンでピクセル間隔は固定できません。
  • 外部への辺はサブグラフの方向を上書きする場合があります。
  • アイコンにはパック、画像には取得可能な素材、ELKには登録が必要です。

よくある質問 (FAQ)

新しい図形を使うには?
A@{ shape: 名前, label: "表示名" }でカタログの名前または別名を指定します。
内部方向が無視されるのはなぜ?
内部と外部のノードをつなぐと、サブグラフが全体の方向を継承する場合があります。
一つの辺だけ変えるには?
0始まりの番号でlinkStyleを使うか、辺のidにスタイルクラスを適用します。