Mermaid.NET.Flowcharts 3.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Mermaid.NET.Flowcharts --version 3.1.0
                    
NuGet\Install-Package Mermaid.NET.Flowcharts -Version 3.1.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Mermaid.NET.Flowcharts" Version="3.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Mermaid.NET.Flowcharts" Version="3.1.0" />
                    
Directory.Packages.props
<PackageReference Include="Mermaid.NET.Flowcharts" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Mermaid.NET.Flowcharts --version 3.1.0
                    
#r "nuget: Mermaid.NET.Flowcharts, 3.1.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Mermaid.NET.Flowcharts@3.1.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Mermaid.NET.Flowcharts&version=3.1.0
                    
Install as a Cake Addin
#tool nuget:?package=Mermaid.NET.Flowcharts&version=3.1.0
                    
Install as a Cake Tool

Mermaid.NET.Flowcharts

A lightweight .NET library for generating Mermaid flowchart markup. Mermaid.NET.Flowcharts focuses on the core features of Mermaid flowcharts without unnecessary complexity.

Features

  • Support for all standard Mermaid node shapes
  • Customizable link types and directions
  • Subgraph support
  • Unicode text support
  • Node styling
  • Link styling

To be added

Basic Usage

Mermaid.NET.Flowcharts allows you to quickly define nodes and links between nodes so that you can add them to a flowchart. The ToMermaidString() method handles the formatting of the output automatically, allowing you to copy and paste the output inside a Mermaid block to render it in Markdown.

using Mermaid.Flowcharts;
using Mermaid.Flowcharts.Nodes;
using Mermaid.Flowcharts.Links;

// Create a new flowchart
FlowchartTitle flowchartTitle = FlowchartTitle.FromString("Basic usage");
Flowchart flowchart = new(flowchartTitle);

// Create nodes
Node start = Node.Create("start", "Start");
Node process = Node.Create("process", "Process Data");
Node stop = Node.Create("stop", "Stop");

// Create links
Link startToProcess = new(start, process, default);
Link processToEnd = new(process, stop, default);

// Add nodes and links to the flowchart
flowchart
    .AddNode(start)
    .AddNode(process)
    .AddNode(stop)
    .AddLink(startToProcess)
    .AddLink(processToEnd);

// Generate the Mermaid output
string mermaid = flowchart.ToMermaidString();

Will generate the following Mermaid output:

---
title: Basic usage
---
flowchart TD
  start["Start"]
  process["Process Data"]
  stop["Stop"]

  start ---> process
  process ---> stop

Advanced features

Node shapes

Use the Node.Create factory method with a custom NodeShape to generate nodes with different shapes. Nodes are rectangular by default.

using Mermaid.Flowcharts;
using Mermaid.Flowcharts.Nodes;

// Create a new flowchart
FlowchartTitle flowchartTitle = FlowchartTitle.FromString("Various node shapes");
Flowchart flowchart = new(flowchartTitle);

// Create nodes with various shapes
Node rectangle = Node.Create("rectangle", "Rectangle", NodeShape.Rectangle);
Node rounded = Node.Create("rounded", "RoundedEdges", NodeShape.RoundedEdges);
Node stadium = Node.Create("stadium", "Stadium", NodeShape.Stadium);
Node subroutine = Node.Create("subroutine", "Subroutine", NodeShape.Subroutine);
Node cylindrical = Node.Create("cylindrical", "Cylindrical", NodeShape.Cylindrical);
Node circle = Node.Create("circle", "Circle", NodeShape.Circle);
Node doubleCircle = Node.Create("doubleCircle", "DoubleCircle", NodeShape.DoubleCircle);
Node asymmetric = Node.Create("asymmetric", "Asymmetric", NodeShape.Asymmetric);
Node rhombus = Node.Create("rhombus", "Rhombus", NodeShape.Rhombus);
Node hexagon = Node.Create("hexagon", "Hexagon", NodeShape.Hexagon);
Node parallelogram = Node.Create("parallelogram", "Parallelogram", NodeShape.Parallelogram);
Node parallelogramAlt = Node.Create("parallelogramAlt", "ParallelogramAlt", NodeShape.ParallelogramAlt);
Node trapezoid = Node.Create("trapezoid", "Trapezoid", NodeShape.Trapezoid);
Node trapezoidAlt = Node.Create("trapezoidAlt", "TrapezoidAlt", NodeShape.TrapezoidAlt);

// Add the nodes to the flowchart
flowchart
    .AddNode(rectangle)
    .AddNode(rounded)
    .AddNode(stadium)
    .AddNode(subroutine)
    .AddNode(cylindrical)
    .AddNode(circle)
    .AddNode(doubleCircle)
    .AddNode(asymmetric)
    .AddNode(rhombus)
    .AddNode(hexagon)
    .AddNode(parallelogram)
    .AddNode(parallelogramAlt)
    .AddNode(trapezoid)
    .AddNode(trapezoidAlt);

// Generate the Mermaid output
string mermaid = flowchart.ToMermaidString();

Will generate the following Mermaid output:

---
title: Various node shapes
---
flowchart TD
  rectangle["Rectangle"]
  rounded("RoundedEdges")
  stadium(["Stadium"])
  subroutine[["Subroutine"]]
  cylindrical[("Cylindrical")]
  circle(("Circle"))
  doubleCircle((("DoubleCircle")))
  asymmetric>"Asymmetric"]
  rhombus{"Rhombus"}
  hexagon{{"Hexagon"}}
  parallelogram[/"Parallelogram"/]
  parallelogramAlt[\"ParallelogramAlt"\]
  trapezoid[/"Trapezoid"\]
  trapezoidAlt[\"TrapezoidAlt"/]

When creating a link between nodes, you can specify a LinkType. The link type lets you define the thickness, the direction and the arrow type of a link.

using Mermaid.Flowcharts;
using Mermaid.Flowcharts.Nodes;
using Mermaid.Flowcharts.Links;

// Create a new flowchart
FlowchartTitle flowchartTitle = FlowchartTitle.FromString("Link types");
Flowchart flowchart = new(flowchartTitle);

// Create two nodes
Node a = Node.Create("a", "A");
Node b = Node.Create("b", "B");

// Create links with specific types and text
LinkType arrowLeftToRightNormal = LinkType.Create(LinkArrowType.Arrow, LinkDirection.FromTo, LinkThickness.Normal);
Link arrowLeftToRightNormalLink = Link.Create(a, b, arrowLeftToRightNormal);
LinkType circleRightToLeftDotted = LinkType.Create(LinkArrowType.Circle, LinkDirection.ToFrom, LinkThickness.Dotted);
Link circleRightToLeftDottedLink = Link.Create(a, b, circleRightToLeftDotted);
LinkType crossBothThick = LinkType.Create(LinkArrowType.Cross, LinkDirection.Both, LinkThickness.Thick);
Link crossBothThickLink = Link.Create(a, b, crossBothThick);
LinkType noneNormal = LinkType.Create(LinkArrowType.None, LinkDirection.Both, LinkThickness.Normal);
Link noneNormalTextLink = Link.Create(a, b, noneNormal, "link text");

// Add nodes and links to the flowchart
flowchart
    .AddNode(a)
    .AddNode(b)
    .AddLink(arrowLeftToRightNormalLink)
    .AddLink(circleRightToLeftDottedLink)
    .AddLink(crossBothThickLink)
    .AddLink(noneNormalTextLink);

// Generate the Mermaid output
string mermaid = flowchart.ToMermaidString();

Will generate the following Mermaid output:

---
title: Link types
---
flowchart TD
  a["A"]
  b["B"]

  a ---> b
  a o-.- b
  a x===x b
  a ---|link text| b

Subgraphs

It is also possible to create subgraphs, which are a type of node that can themselves contain nodes. Subgraphs can be nested within subgraphs, and links can exist between them. However, all links are managed on the flowchart level, not on the subgraph level.

using Mermaid.Flowcharts;
using Mermaid.Flowcharts.Nodes;
using Mermaid.Flowcharts.Links;

// Create a new flowchart with a node
FlowchartTitle flowchartTitle = FlowchartTitle.FromString("Using subgraphs");
Flowchart flowchart = new(flowchartTitle);
Node node = Node.Create("n", "Node");
flowchart.AddNode(node);

// Create a subgraph with one node
Subgraph subgraph = Subgraph.Create<MermaidUnicodeText>("sg", "Subgraph");
Node subnode = Node.Create("sn", "Subnode");
subgraph.AddNode(subnode);

// Create a subsubgraph with a node inside subgraph
Subgraph subsubgraph = Subgraph.Create<MermaidUnicodeText>("ssg", "Subsubgraph");
Node subsubnode = Node.Create("ssn", "Subsubnode");
subsubgraph.AddNode(subsubnode);

// Add the subsubgraph to the subgraph
subgraph.AddNode(subsubgraph);

// Add the subgraph to the flowchart
flowchart.AddNode(subgraph);

// Create a link between the flowchart node and the subsubgraph
Link nodeToSubSubGraph = Link.Create(node, subsubgraph, default);
flowchart.AddLink(nodeToSubSubGraph);

// Create a link between the flowchart node and the subnode
Link nodeToSubnode = Link.Create(node, subnode, default);
flowchart.AddLink(nodeToSubnode);

// Generate the Mermaid output
string mermaid = flowchart.ToMermaidString();

Will generate the following Mermaid output:

---
title: Using subgraphs
---
flowchart TD
  n["Node"]
  sn["Subnode"]

  subgraph sg ["Subgraph"]
    sn["Subnode"]

    subgraph ssg ["Subsubgraph"]
      ssn["Subsubnode"]
    end
  end
  subgraph ssg ["Subsubgraph"]
    ssn["Subsubnode"]
  end

  n ---> ssg
  n ---> sn

Styling

In Mermaid, both nodes and links can be styled using a style class. The corresponding type in Mermaid.NET.Flowcharts is called StyleClass. This type wraps some common style attributes, such as:

  • fill color
  • stroke color
  • stroke width
  • font size
  • etc.
Styling nodes

In Mermaid, nodes can be through a style class definitions, which show up as classDef inside the flowchart. To do this, you must create a NodeStyle with a given name and a StyleClass and use that node style when creating a node. If you create multiple nodes using the same node style, they will be grouped together automatically when applying the style class.

using Mermaid.Flowcharts;
using Mermaid.Flowcharts.Nodes;

// Create a new flowchart
FlowchartTitle flowchartTitle = FlowchartTitle.FromString("Styling nodes");
Flowchart flowchart = new(flowchartTitle);

// Define a style class
StyleClass nodeStyleClass = new(Fill: new Fill(Color.FromHex("#ff9966")));

// Create a named node style
NodeStyle nodeStyle = new("customStyle", nodeStyleClass);

// Create two nodes with the node style
Node a = Node.Create("a", "A", nodeStyle: nodeStyle);
Node b = Node.Create("b", "B", nodeStyle: nodeStyle);

// Add the nodes to the flowchart
flowchart
    .AddNode(a)
    .AddNode(b);

// Generate the Mermaid output
string mermaid = flowchart.ToMermaidString();

Will generate the following Mermaid output:

---
title: Styling nodes
---
flowchart TD
  a["A"]
  b["B"]

  classDef customStyle fill:#ff9966
  class a,b customStyle

Styling links does not require a separate class, you directly apply a StyleClass to them. Due to the fact that links don't have IDs, they are grouped together by index (counter in order of appearance).

using Mermaid.Flowcharts;
using Mermaid.Flowcharts.Nodes;
using Mermaid.Flowcharts.Links;

// Create a new flowchart
FlowchartTitle flowchartTitle = FlowchartTitle.FromString("Styling links");
Flowchart flowchart = new(flowchartTitle);

// Define some nodes
Node a = Node.Create("a", "A");
Node b = Node.Create("b", "B");
Node c = Node.Create("c", "C");

// Define a style class
StyleClass linkStyleClass = new(
    Stroke: new Stroke(Color.FromHex("#ff6b6b")),
    StrokeWidth: StrokeWidth.Length(2, Unit.Px));

// Create some links
Link ab = Link.Create(a, b, linkStyle: linkeStyleClass);
Link bc = Link.Create(b, c, linkStyle: linkeStyleClass);

// Add the nodes and links to the flowchart
flowchart
    .AddNode(a)
    .AddNode(b)
    .AddNode(c)
    .AddLink(ab)
    .AddLink(bc);

// Generate the Mermaid output
string mermaid = flowchart.ToMermaidString();

Will generate the following Mermaid output:

---
title: Styling links
---
flowchart TD
  a["A"]
  b["B"]
  c["C"]

  a ---> b
  b ---> c

  linkStyle 0,1 stroke:#ff6b6b,stroke-width:2px

You can define multiple node styles and link styles in a single flowchart.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net10.0

    • No dependencies.
  • net8.0

    • No dependencies.
  • net9.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Mermaid.NET.Flowcharts:

Package Downloads
SharpView.Export.Mermaid

Formats SharpView project maps and call diagrams as Mermaid flowcharts in Markdown, with source-evidence tables.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
6.0.0 184 8/15/2026
5.0.0 122 8/14/2026
4.1.0 161 1/20/2026
4.0.0 167 11/28/2025
3.1.0 172 11/28/2025
3.0.0 255 8/25/2025