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.

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]
The example combines bar and line series over monthly categories. Values are illustrative. Matching the number and order of values to the category list is essential for an accurate chart.

Syntax and interpretation

ConceptHow to apply it
CategoriesKeep one value per category in each series. Missing or reordered values can change the meaning of the chart.
BaselineA truncated y-axis can exaggerate bar differences. Choose and explain bounds appropriate to the measurement.
Series choiceUse 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.