Mermaid XY Chart Maker
Write XY charts in Mermaid code and watch them render as you type. Start from the example below, then export PNG or SVG, share a link or embed the diagram.
Updated · Code editor with live preview
XY chart example
Rendering preview…
xychart-beta
title "Monthly recurring revenue"
x-axis [jan, feb, mar, apr, may, jun]
y-axis "Revenue (USD)" 0 --> 12000
bar [3200, 4100, 5300, 6900, 8800, 11200]
line [3200, 4100, 5300, 6900, 8800, 11200]What is an XY chart?
An XY chart plots values against a horizontal scale as bars, as a line, or as both together. It is the ordinary bar-and-line chart of business reporting, written as text rather than built in a spreadsheet. In Mermaid you write one as a block starting with the xychart-beta keyword.
When to use an XY chart
- Revenue, signups or usage over time
- Before-and-after comparisons in a report
- Benchmark results in technical documentation
- Any chart that belongs in version control rather than a spreadsheet
How to make an XY chart in Mermaid
- Step 1
Open the editor
Open TryMermaid with the example on this page, or start a new diagram with xychart-beta on the first line.
- Step 2
Set up the axes
Add a title, then list the categories on the x-axis line, such as x-axis [jan, feb, mar].
- Step 3
Plot the data
Add a bar line, a line line, or both, each holding one value per category in the same order.
- Step 4
Export or share
Check the live preview, then export as PNG or SVG or copy a share link.
XY chart syntax cheat sheet
| Element | Syntax | What it does |
|---|---|---|
| Start | xychart-beta | Begins an XY chart |
| Title | title "Revenue" | Heading above the chart |
| X axis | x-axis [jan, feb, mar] | Categories along the bottom |
| Y axis | y-axis "Revenue" 0 --> 12000 | Label and range for the vertical scale |
| Bars | bar [3200, 4100, 5300] | One value per category |
| Line | line [3200, 4100, 5300] | Same values drawn as a line |
XY chart FAQ
Can a Mermaid XY chart show bars and a line together?
Yes. Give both a bar line and a line line with the same values, as the example on this page does, and Mermaid draws the line over the bars.
How do I control the y-axis range?
Set the range explicitly on the y-axis line, as in y-axis "Revenue (USD)" 0 --> 12000. Without a range Mermaid picks one from the data.
Can I rotate the chart?
Add vertical after the keyword, as in xychart-beta vertical, to turn the chart on its side. The default orientation is horizontal.