Appearance
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
| Name | Default | Type | Description |
|---|---|---|---|
data | [] | Array | The dataset |
minAngle | 0.3 | Number | The minimum arc angle needed to display label |
cornerRadius | 3 | Number | The amount of rounding for arc corners |
padAngle | 0.02 | Number | The space between arcs |
innerRadius | 0.67 | Number | The size of the inner circle |
minAngle | 0.3 | Number | The minimum angle needed to display label on arc |
duration | 500 | Number | The time of the animation in ms |
showLabels | true | Boolean | Whether or not to show name labels |
labelsOutside | false | Boolean | Whether or not to show labels outside of donut |
showCount | false | Boolean | Whether or not to show the count in the label |
labelClass | font-semibold text-sm | String | The styles for name labels |
valueClass | text-sm | String | The styles for value labels |
bgColor | null | String | The color for the background of donut |
format | d => d.toFixed(1) + '%' | Function | Formatter for percentage label |
title | '' | String | The aria label for accessibility |
id | '' | String | The id for aria label |
Events
| Name | Argument | Description |
|---|---|---|
@select | { target, data } | Emitted when arc is clicked |
@hover | { target, data } | null | Emitted when arc is hovered |
Dependencies
- d3