Navigation

v2.1.0
Parts of a whole

Donut chart

The parts of a whole around one figure that stands in the middle.

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.

Donut

<div class="card max-w(480) mx-auto">  <div class="card-header">    <h3 class="card-title">Storage</h3>    <p class="card-description">248 GB of 500 GB used</p>  </div>  <figure class="chart chart-split" id="storage" style="--chart-size: 10rem"></figure></div><script>addEventListener('DOMContentLoaded', function () {MasterUI.chart(document.getElementById('storage'), {  type: 'donut',  label: 'Storage used by kind, in gigabytes',  center: { value: '248 GB', label: 'Used' },  format: function (value) { return value + ' GB' },  series: [    { name: 'Photos', value: 112 },    { name: 'Video', value: 74 },    { name: 'Documents', value: 38 },    { name: 'Other', value: 24 }  ]})})</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">Storage</h3>    <p className="card-description">248 GB of 500 GB used</p>  </div>  <Chart    className="chart-split"    id="storage"    style={{ '--chart-size': '10rem' } as React.CSSProperties}    type="donut"    label="Storage used by kind, in gigabytes"    center={{ value: '248 GB', label: 'Used' }}    format={function (value) { return value + ' GB' }}    series={[      { name: 'Photos', value: 112 },      { name: 'Video', value: 74 },      { name: 'Documents', value: 38 },      { name: 'Other', value: 24 }    ]}  /></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">Storage</h3>    <p class="card-description">248 GB of 500 GB used</p>  </div>  <Chart    class="chart-split"    id="storage"    style="--chart-size: 10rem"    type="donut"    label="Storage used by kind, in gigabytes"    center={{ value: '248 GB', label: 'Used' }}    format={function (value) { return value + ' GB' }}    series={[      { name: 'Photos', value: 112 },      { name: 'Video', value: 74 },      { name: 'Documents', value: 38 },      { name: 'Other', value: 24 }    ]}  /></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">Storage</h3>      <p class="card-description">248 GB of 500 GB used</p>    </div>    <Chart      class="chart-split"      id="storage"      style="--chart-size: 10rem"      type="donut"      label="Storage used by kind, in gigabytes"      :center="{ value: '248 GB', label: 'Used' }"      :format="function (value) { return value + ' GB' }"      :series="[        { name: 'Photos', value: 112 },        { name: 'Video', value: 74 },        { name: 'Documents', value: 38 },        { name: 'Other', value: 24 }      ]"    />  </div></template>

A donut keeps its middle for one figure, the total or the part that matters, given as center. While a slice is under the pointer the middle says that slice's value and name instead, so nothing covers the ring. chart-split on the chart stands the legend beside the plot as a column, with each slice's share at its end, and puts it under the plot 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
hole, center.7, noneA donut's hole, and what stands in the middle of a donut or rings
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.