Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Cover image for Making Pie (Charts) out of Mermaid.js
Matt Eland
Matt ElandSubscriber

Posted on • Originally published atnewdevsguide.com

     

Making Pie (Charts) out of Mermaid.js

I love the myriad of types of diagrams thatMermaid.js can generate fromsequence diagrams touser journey maps toclass diagrams. However, I have to admit that I was somewhat surprised to discover that in addition to these specialized charts, Mermaid.js can also generate the most basic of all charts: thepie chart.

In this short article I'll show you the basic syntax for representing a pie chart in Mermaid.js.

First of all, Mermaid.js works in a variety of settings from GitHub markdown toPolyglot Notebooks and various add-ins for tools like Jira and Wordpress. I go into the process for integrating Mermaid.js a bit more in my article onentity relationship diagrams if you are curious about the overall context.

With Mermaid, you can make a simple pie chart with the simple pie keyword, followed optionally by a title and then individual data points formatted as "Data Point": value.

Here's a simple Mermaid.js Pie Chart illustrating the leading causes of developer tears from 65 respondents:

pie   title Leading Causes of Developer Tears   "JavaScript": 42   "DNS": 8   "Leaving a VM on": 15
Enter fullscreen modeExit fullscreen mode

A Pie Chart

That simple markdown is all you need to render a pie chart using Mermaid.js.

There are a couple of things here I want to highlight before I close this article:

  1. The values do not need to add up to 100. Mermaid.js figures out the total percentage by the total value count
  2. The values do not need to be in a particular order. Mermaid.js will organize the chart in descending order automatically

There are a few more ways of customizing pie charts in Mermaid.js so I'd encourage you to read theMermaid.js pie chart documentation for full theming reference, but pie charts on their own are very simple and easy to add to your application.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

AI Specialist and Wizard at Leading EDJE, Book and Course Author, and Microsoft MVP
  • Location
    Columbus, OH
  • Education
    Master's of Science in Data Analytics, B.S. Computer Information Systems
  • Pronouns
    He/Him
  • Work
    AI Specialist and Wizard at Leading EDJE
  • Joined

More fromMatt Eland

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp