Skip to content

Pie Chart: 0% Label Renders Awkwardly, and Negative Values Crash Parser with Unclear Error #6584

@BambioGaming

Description

@BambioGaming

Description

When using the pie chart in Mermaid.js:

  • A slice with a value of 0 is rendered with a 0% label that overlaps the edge of the chart.
  • A slice with a negative value causes a MermaidParseError with an unclear error message.
  • The documentation does not mention these limitations, which may confuse users generating values dynamically.

Steps to reproduce

  1. Open the Mermaid Live Editor
  2. Paste the following diagram:
pie
  title Zero and Negative Values
  "Valid Slice" : 30
  "Zero Slice" : 0
  "Negative Slice" : -10

Actual Behavior

  • Mermaid fails to render the diagram.
  • Console shows a vague parser error:
    MermaidParseError: Parsing failed: unexpected character: - at offset: 81
  • The reason (negative value) is not explained.

If "Negative Slice" is removed:

pie
  title Zero and Negative Values
  "Valid Slice" : 30
  "Zero Slice" : 0
  • Diagram renders.
  • The "Zero Slice" appears in the legend and shows a 0% label at the top, overlapping the chart's border.
  • This creates misleading visuals in a data visualization.

Screenshots

  1. Chart with awkward 0% label placement

Image

  1. Console error for negative value

Image

Code Sample


Setup

  • Mermaid version: 11.6.0
  • Browser: Chrome 124
  • OS: Windows 11

Suggested Solutions

For Negative Values:

  • Reject them at parse time with a clear error message, such as: "Negative values are not allowed in pie charts. All slice values must be ≥ 0."

For Zero Values:

  • Option 1: Exclude them from the chart entirely.
  • Option 2: Render them without label, or place label inside the pie in a non-overlapping position.
  • Option 3: Add support for a hideZeroSlices: true flag in config.

Documentation:
Update Pie Chart Docs to explain behavior for 0 and negative values.

Additional Context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions