About FlowchartJS
FlowchartJS lets you create interactive diagrams and visualizations using text and code.
It is a lightweight JavaScript library that renders Mermaid-inspired text definitions to create flowcharts dynamically. Zero dependencies, pure Vanilla JS.
If you are familiar with Mermaid syntax, you should have no problem learning FlowchartJS Syntax.
Getting Started
Include the CSS and JS files in your HTML:
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/Mrithul-E/FlowchartJS/docs/dist/flowchart.css">
<script src="https://cdn.jsdelivr.net/gh/Mrithul-E/FlowchartJS/docs/dist/flowchart.js"></script>
Create a container and initialize the chart:
<div id="my-chart"></div>
<script>
const chart = new FlowChart('my-chart', {
theme: 'dark',
interactive: true
});
chart.render(`
graph TD
A[Start] --> B{Decision}
B --> |Yes| C[Action]
B --> |No| D[End]
`);
</script>
Syntax Guide
FlowchartJS uses a simple text-based syntax similar to Mermaid:
graph TD
A[Node A] --> B[Node B]
B --> C{Decision}
C --> |Yes| D[Result]
C --> |No| E[Alternative]
Node Shapes
Use different bracket styles to define node shapes:
Edge Types
| Syntax | Type | Description |
|---|---|---|
--> |
Arrow | Standard arrow connection |
--- |
Open | Line without arrow |
-.->
|
Dotted | Dotted line with arrow |
==> |
Thick | Thick arrow |
-->|label| |
Labeled | Arrow with label |
Direction
Set the flow direction with the graph declaration:
| Syntax | Direction |
|---|---|
graph TD |
Top to Down |
graph LR |
Left to Right |
Styling & Classes
Customize the look of nodes and edges using standard styling directives.
Link Styling
Style individual or multiple links using linkStyle. Supports standard SVG stroke
properties and curve type.
graph TD
A[Start] --> B[Step]
B --> C[Linear]
linkStyle 0 stroke:#ff0000,stroke-width:4px,curve:step
linkStyle 1 stroke:blue,curve:linear
Supported curve types: bezier (default), linear, step,
stepAfter, stepBefore.
Node Styling
Apply inline styles to specific nodes using style:
style id1 fill:#f9f,stroke:#333,stroke-width:4px,color:#fff
Classes
Define reusable classes with classDef and apply them using class or the
::: shorthand.
classDef error fill:#ff0000,color:#fff
classDef success fill:#00ff00,color:#000
A:::error --> B:::success
class A error
class B success
Configuration Options
| Option | Type | Default | Description |
|---|---|---|---|
theme |
string | 'light' | 'light' or 'dark' |
interactive |
boolean | true | Enable pan/zoom |
layout.nodeWidth |
number | 140 | Default node width |
layout.nodeHeight |
number | 50 | Default node height |
Themes
FlowchartJS supports light and dark themes:
// Initialize with dark theme
const chart = new FlowChart('chart', { theme: 'dark' });
// Switch theme dynamically
chart.setTheme('light');
API Methods
| Method | Description |
|---|---|
render(input) |
Renders the chart from text input |
setTheme(theme) |
Switches between 'light' and 'dark' |
exportImage() |
Downloads as PNG |
exportSVG() |
Downloads as SVG |
Export PNG
Export the current chart as a PNG image:
chart.exportImage();
Export SVG
Export the current chart as an SVG file:
chart.exportSVG();