Mermaid Bar Chart Syntax & Examples
Use the xychart syntax to compare categories with Mermaid bars. The example below includes labeled categories, a numeric y-axis, and a copyable bar data array.
MERMAID EXAMPLE
Mermaid bar chart example
Copy the working code, replace the labels and values, then continue editing the same diagram in Mermaid Studio.
Compare feature usage
Summarize category metrics
Present a small set of business or engineering values
xychart title "Monthly signups" x-axis [1Month, 2Month, 3Month, 4Month] y-axis "Signups" 0 --> 100 bar [20, 35, 58, 82]
xychart
title "Monthly signups"
x-axis [1Month, 2Month, 3Month, 4Month]
y-axis "Signups" 0 --> 100
bar [20, 35, 58, 82]xychart
title "Monthly signups"
x-axis [1Month, 2Month, 3Month, 4Month]
y-axis "Signups" 0 --> 100
bar [20, 35, 58, 82]SYNTAX
Mermaid bar chart syntax
Learn the small set of Mermaid keywords that make this chart work.
| Syntax | What it does |
|---|---|
| xychart | Starts an XY chart. Add horizontal after the header for a horizontal orientation. |
| title | Adds a short description above the chart. |
| x-axis | Defines category labels and their order. |
| y-axis | Defines the numeric range and optional axis title. |
| bar [values] | Draws one bar for each numeric value. |
The current Mermaid documentation uses xychart and xychart horizontal. xychart-beta is retained by Mermaid Studio as a legacy input alias.
CODE EXAMPLES
More Bar Chart examples
TROUBLESHOOTING
Common Bar Chart errors
FAQ
Frequently asked questions
What is a bar chart best for?+
Bar charts are best for comparing separate categories where the difference between values should be immediately visible.
Should a bar chart axis start at zero?+
Usually yes, especially when bar length is used to compare magnitude directly.
How do I make a bar chart in Mermaid?+
Start with xychart, add an x-axis for categories, a y-axis for the numeric range, and a bar array with one value per category.
Does Mermaid support horizontal bar charts?+
Yes. Use xychart horizontal and keep the same bar data syntax.
How do I show values on Mermaid bars?+
Use the xyChart configuration with showDataLabel: true. This option is available in Mermaid v11.14.0 and later.
RELATED GUIDES
Keep exploring Mermaid charts
TEMPLATES
Start from a related template
Ready to make a Bar Chart?
Open the editor with a working example and adapt it to your project.
Start in Mermaid Studio