Mermaid Line Chart Syntax & Examples
Use xychart with a line data array to show change across time or another ordered sequence. Copy the example below and replace the labels and values.
MERMAID EXAMPLE
Mermaid line chart example
Copy the working code, replace the labels and values, then continue editing the same diagram in Mermaid Studio.
Show product growth
Track service metrics
Explain changes across a timeline
xychart title "Monthly active users" x-axis [1Month, 2Month, 3Month, 4Month] y-axis "User" 0 --> 100 line [20, 38, 52, 78]
xychart
title "Monthly active users"
x-axis [1Month, 2Month, 3Month, 4Month]
y-axis "User" 0 --> 100
line [20, 38, 52, 78]xychart
title "Monthly active users"
x-axis [1Month, 2Month, 3Month, 4Month]
y-axis "User" 0 --> 100
line [20, 38, 52, 78]SYNTAX
Mermaid line chart syntax
Learn the small set of Mermaid keywords that make this chart work.
| Syntax | What it does |
|---|---|
| xychart | Starts an XY chart. Use xychart horizontal when the chart should run horizontally. |
| x-axis | Defines the ordered categories or dates used by the line. |
| y-axis | Defines the numeric range and unit for the values. |
| line [values] | Draws a line through one numeric value per x-axis item. |
| value "label" | Adds an optional point label in current Mermaid versions. |
The current Mermaid documentation uses xychart. Optional per-point line labels are documented for Mermaid v11.16.0 and later.
CODE EXAMPLES
More Line Chart examples
TROUBLESHOOTING
Common Line Chart errors
FAQ
Frequently asked questions
What is a line chart used for?+
Line charts are useful for showing how a value changes across time or another naturally ordered sequence.
Can Mermaid line charts show multiple series?+
The XY chart syntax can represent chart values in a compact, code-based format for comparison and trend documentation.
How do I make a line chart in Mermaid?+
Start with xychart, define an ordered x-axis and numeric y-axis, then add a line array with one value for each x-axis item.
Can Mermaid combine bar and line charts?+
Yes. Add both bar and line series under the same xychart definition when the values share a meaningful scale.
Can line chart points have labels?+
Current Mermaid versions support optional quoted labels after line values. Verify the renderer version before sharing this syntax.
RELATED GUIDES
Keep exploring Mermaid charts
TEMPLATES
Start from a related template
Ready to make a Line Chart?
Open the editor with a working example and adapt it to your project.
Start in Mermaid Studio