Skip to content
On this page

Charts > Donut Chart ​

A donut chart presents information in the form of a ring, with the central area often left blank, conveying data through the proportionate arc lengths of different segments.

The Chart ​

Download example CSV
Copy HTML

%

Other compatible charts

Playground ​

Data

Number of categories

Animation

Duration of animation in ms

Style

Color for each segment
Color of labels
Rounding of segment corners
Padding between segments
Size of inner circle
Show name label
Show count next to percentage
Show labels outside donut
Color of background

Component API ​

The donut chart is built using SVG and d3. You can make it a pie chart by setting innerRadius to 0.

The arcs are animated using d3 transition with a custom interpolator using attrTween.

Usage Example (with tooltip) ​

vue
<template>
  <DonutChart :data="data" @hover="setTooltip" />
  <OTTooltip :info="tooltip">
    <p>
      <span class="font-semibold">{{ tooltip.name }}</span> {{ tooltip.value }}%
    </p>
  </OTTooltip>
</template>

<script setup>
import useTooltip from "@/functions/useTooltip.js";

const [tooltip, setTooltip] = useTooltip();
</script>

Data ​

js
[
  {
    id: "data-1",
    name: "Data 1",
    values: {
      val1: {
        id: "val-1",
        name: "Val 1",
        value: 75,
        count: 3,
        color: "#eee",
      },
      val2: {
        id: "val-2",
        name: "Val 2",
        value: 25,
        count: 1,
        color: "#ccc",
      },
    },
  },
];

Props ​

NameDefaultTypeDescription
data[]ArrayThe dataset
minAngle0.3NumberThe minimum arc angle needed to display label
cornerRadius3NumberThe amount of rounding for arc corners
padAngle0.02NumberThe space between arcs
innerRadius0.67NumberThe size of the inner circle
minAngle0.3NumberThe minimum angle needed to display label on arc
duration500NumberThe time of the animation in ms
showLabelstrueBooleanWhether or not to show name labels
labelsOutsidefalseBooleanWhether or not to show labels outside of donut
showCountfalseBooleanWhether or not to show the count in the label
labelClassfont-semibold text-smStringThe styles for name labels
valueClasstext-smStringThe styles for value labels
bgColornullStringThe color for the background of donut
formatd => d.toFixed(1) + '%'FunctionFormatter for percentage label
title''StringThe aria label for accessibility
id''StringThe id for aria label

Events ​

NameArgumentDescription
@select{ target, data }Emitted when arc is clicked
@hover{ target, data } | nullEmitted when arc is hovered

Dependencies ​

  • d3