Navigation

v2.1.0
Parts of a whole

Pie chart

What one whole is made of, as slices of a circle or a donut, best kept to five parts or fewer.

On this page

A pie and a donut show what a whole is made of. Each slice is its share of the sum, kept a constant gap from its neighbors, with its corners turned. Keep a whole to five parts or fewer and fold the rest into "Other": a sixth sliver is not read.

Pie

<div class="card max-w(480) mx-auto">  <div class="card-header">    <h3 class="card-title">Browsers</h3>    <p class="card-description">Share of sessions this month</p>  </div>  <figure class="chart chart-split" id="browsers" style="--chart-size: 10rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('browsers'), {  type: 'pie',  label: 'Share of sessions by browser, in percent',  format: function (value) { return value + '%' },  series: [    { name: 'Chrome', value: 58 },    { name: 'Safari', value: 24 },    { name: 'Firefox', value: 9 },    { name: 'Edge', value: 6 },    { name: 'Other', value: 3 }  ]})})</script><script type="module">  import { attach } from '@master/ui/behaviors'  attach()</script>
import { Chart } from './ui/chart'<div className="card max-w(480) mx-auto">  <div className="card-header">    <h3 className="card-title">Browsers</h3>    <p className="card-description">Share of sessions this month</p>  </div>  <Chart    className="chart-split"    id="browsers"    style={{ '--chart-size': '10rem' } as React.CSSProperties}    type="pie"    label="Share of sessions by browser, in percent"    format={function (value) { return value + '%' }}    series={[      { name: 'Chrome', value: 58 },      { name: 'Safari', value: 24 },      { name: 'Firefox', value: 9 },      { name: 'Edge', value: 6 },      { name: 'Other', value: 3 }    ]}  /></div>
<script>  import Chart from './ui/Chart.svelte'</script><div class="card max-w(480) mx-auto">  <div class="card-header">    <h3 class="card-title">Browsers</h3>    <p class="card-description">Share of sessions this month</p>  </div>  <Chart    class="chart-split"    id="browsers"    style="--chart-size: 10rem"    type="pie"    label="Share of sessions by browser, in percent"    format={function (value) { return value + '%' }}    series={[      { name: 'Chrome', value: 58 },      { name: 'Safari', value: 24 },      { name: 'Firefox', value: 9 },      { name: 'Edge', value: 6 },      { name: 'Other', value: 3 }    ]}  /></div>
<script setup>import Chart from './ui/Chart.vue'</script><template>  <div class="card max-w(480) mx-auto">    <div class="card-header">      <h3 class="card-title">Browsers</h3>      <p class="card-description">Share of sessions this month</p>    </div>    <Chart      class="chart-split"      id="browsers"      style="--chart-size: 10rem"      type="pie"      label="Share of sessions by browser, in percent"      :format="function (value) { return value + '%' }"      :series="[        { name: 'Chrome', value: 58 },        { name: 'Safari', value: 24 },        { name: 'Firefox', value: 9 },        { name: 'Edge', value: 6 },        { name: 'Other', value: 3 }      ]"    />  </div></template>

#The legend beside it

chart-split on the chart stands the legend beside the pie as a column, with each slice's share at its end, and puts it under the pie when there is no room.

A pie is the same with no hole. --chart-size is the width of either, 12rem by default, and hole is the hole's share of a donut's radius, .7 by default.

#Pie or donut

A donut keeps its middle for one figure; a pie gives the slices the whole circle. Parts read along one bar are a breakdown.

#Options

OptionDefault
labelnoneWhat the chart shows and in what unit: the plot's accessible name
series[]Each with a name and values, a value for a slice or a ring, or points for a scatter; optionally a category, a type and a ring's max
format, tickFormatthe locale'sHow a value and a tick are written; xFormat for a scatter's scale across
legend, togglewith two series, trueWhether a legend is written, and whether its entries are checkboxes

The readout, the keys, the legend, the colors and the scale are the same in every form: Chart holds them, with every option, class and custom property.