Unsaved
Ready
Loading Monaco Editor...
Preview
Styling
All diagram types

Mermaid XY Chart Syntax & Bar Examples

XY charts plot a series as bars, a line, or both. The x-axis is the categories and the y-axis is the range.

Examples

Copy an example, or open it in the live editor with this diagram already loaded.

Quarterly revenue bars

One bar per category. The y-axis range is explicit so the bars do not sit on a scale that starts at zero by surprise.

xychart-beta
    title "Quarterly revenue"
    x-axis [Q1, Q2, Q3, Q4]
    y-axis "Revenue ($k)" 0 --> 120
    bar [40, 55, 70, 90]

Latency as a line

A line is the same list of numbers with line instead of bar. Use it when the categories are ordered, such as months.

xychart-beta
    title "Checkout p95"
    x-axis [Jan, Feb, Mar, Apr]
    y-axis "Milliseconds" 0 --> 500
    line [420, 380, 260, 210]

Bars with a trend line

bar and line can share a chart. Use the same number of values as there are x-axis labels.

xychart-beta
    title "Weekly signups"
    x-axis [Mon, Tue, Wed, Thu, Fri]
    y-axis "Signups" 0 --> 40
    bar [12, 18, 15, 22, 30]
    line [12, 18, 15, 22, 30]

What is a XY Chart?

A Mermaid XY chart is a bar chart, a line chart, or both on one pair of axes. The diagram starts with xychart-beta. x-axis lists the category labels. y-axis sets the title and the numeric range with min --> max. bar and line each take a list of numbers, one per category, in the same order as the x-axis. Use an XY chart to compare amounts or to show a trend. Use a pie chart for shares of one whole.

When to use it

Use an XY chart for revenue by quarter, latency by month, or counts by category. Use a pie chart for a small set of shares. Use a quadrant chart to sort named options into four boxes rather than to plot a series.

Edit this xy chart in the live editor, read the Mermaid cheat sheet, or compare it with Pie Chart, Gantt Chart and Quadrant Chart.

Common Use Cases

  • •Revenue tracking - Visualize sales data over time periods
  • •Performance metrics - Chart KPIs across categories or dates
  • •Comparison analysis - Compare values across different categories
  • •Trend visualization - Show data trends with line charts
  • •Report generation - Create charts for documentation and presentations

Syntax Quick Reference

ElementSyntaxDescription
Titletitle "Chart Title"Chart heading
X-axisx-axis [A, B, C]Category labels
Y-axisy-axis "Label" min --> maxValue axis with range
Bar databar [10, 20, 30]Bar chart data points
Line dataline [10, 20, 30]Line chart data points

Syntax tips

  • •Start with xychart-beta. Quote the title: title "Quarterly revenue".
  • •x-axis [Q1, Q2, Q3, Q4] sets the categories, left to right.
  • •y-axis "Label" 0 --> 120 sets the axis title and the displayed range.
  • •The data lists must have one number per x-axis label, in the same order.
  • •Add both bar and line when you want the raw values and a trend on the same axes.

Common mistakes

Giving the series a different length than the x-axis.

Four labels need four numbers. Add a number or remove a label until the lists match.

Setting a y-axis max below the largest value.

Raise the number after --> so every value sits inside the range.

Using an XY chart for parts of a whole.

Shares of one total are easier to read as a pie chart, as long as there are only a few categories.

Export Options

Charts in a report are often PNG or PDF. SVG is the better choice inside a docs page. Free PNG exports include a watermark.

Got Mermaid code from ChatGPT? Paste it here to render and export instantly.

Get the Free Mermaid Syntax Cheat Sheet

Free Mermaid Syntax Cheat Sheet

All 21 diagram types in one PDF reference.

Frequently Asked Questions

Ready to create your own xy chart?

Open the editor with this example pre-loaded and start customizing.

XY Chart templates

Related Diagram Types

All diagram types