Diagrams / Mermaid XY Chart: Syntax & Examples
Mermaid XY Chart: Syntax & Examples
Explore Mermaid XY syntax for bar and line series. Edit categories and values, review axis bounds and avoid misleading numeric comparisons.
When to use XY Chart
Create a Mermaid XY chart to compare numeric values across categories or an ordered series. Bars emphasize magnitude and lines emphasize progression. Label the axes with units and use a scale that makes the comparison understandable rather than visually exaggerated.
- Start with the example in the editor and identify the elements that answer your question.
- Replace the sample labels and values, previewing after each structural change.
- Review the diagram at its intended reading size, then keep the source and export the format your document accepts.
Read the XY Chart example
Diagram source
xychart-beta
title "Monthly Diagram Exports"
x-axis [Jan, Feb, Mar, Apr, May]
y-axis "Exports" 0 --> 100
bar [42, 58, 73, 81, 96]
line [40, 55, 70, 84, 94]Syntax and interpretation
| Concept | How to apply it |
|---|---|
| Categories | Keep one value per category in each series. Missing or reordered values can change the meaning of the chart. |
| Baseline | A truncated y-axis can exaggerate bar differences. Choose and explain bounds appropriate to the measurement. |
| Series choice | Use lines only when linking adjacent observations is meaningful. Distinct unordered categories often suit bars better. |
Common questions
Does the chart calculate a trend or forecast?
No. It plots the supplied series. Statistical estimates, uncertainty, and future projections need their own calculations and explanation.