Donut Chart

Implement circular data visualizations with the Donut Chart component.

The DonutChart component visualizes proportional data as circular segments with customizable colors and legends. Use it to display percentage-based data in Vue and Nuxt apps. Examples ↗

Basic Usage

Donut Chart with Legend

Filled Donut

Props

PropTypeDefaultDescription
typeDonutType'full'The type of donut chart to render. See DonutType for available options (half or full).
datanumber[]requiredThe data to be displayed in the donut chart. Each number in the array represents a segment value.
arcWidthnumberThe arc width of the chart in pixels.
heightnumberrequiredThe height of the chart in pixels.
radiusnumberrequiredThe radius of the donut in pixels.
hideLegendbooleanfalseIf true, hides the chart legend.
legendPositionLegendPositionOptional position for the legend, if applicable. See LegendPosition for available options.
legendStylestring | Record<string, string>Optional style object for the legend container. Allows custom CSS styling.
categoriesRecord<string, BulletLegendItemInterface>requiredA record mapping category keys to BulletLegendItemInterface objects. This defines the visual representation and labels for each category in the chart's legend.
padAnglenumber0Pad angle between segments in radians.
tooltipTitleFormatter(data: T) => string | numberundefinedCustom formatter for tooltip titles.
hideTooltipbooleanfalseIf true, hides the chart tooltip.
tooltipTooltipConfigundefinedTooltip configuration (hideDelay, showDelay, followCursor).
durationnumberundefinedAnimation duration in milliseconds.

Data Format

The data should be an array of numbers where each number represents a segment value:

type DonutChartData = number[]

Categories Format

Categories define the visual appearance and labels for each segment in the chart's legend:

interface BulletLegendItemInterface {
  name: string
  color: string
}

type DonutCategories = Record<string, BulletLegendItemInterface>

Usage Example

<script setup lang="ts">
const data = ref([35, 25, 20, 15, 5])

const labels = [
  { name: 'Product A', color: '#3b82f6' },
  { name: 'Product B', color: '#22c55e' },
  { name: 'Product C', color: '#f59e0b' },
  { name: 'Product D', color: '#a855f7' },
  { name: 'Other', color: '#06b6d4' },
]

const categories: Record<string, BulletLegendItemInterface> =
  Object.fromEntries(
    labels.map((i) => [i.name, { name: i.name, color: i.color }]),
  )
</script>

<template>
  <DonutChart
    :data="data"
    :height="260"
    :categories="categories"
    :radius="4"
    :arc-width="20"
    :pad-angle="0.1"
  />
</template>

Best Practices & Common Pitfalls

Key-Based Tooltips

The DonutChart uses the keys of the categories object to determine the labels shown in the default tooltip. To ensure your tooltips look "nice and cool", use display-ready strings as keys.

// ❌ Technical keys lead to technical tooltips
const categories = {
  cpu: { name: 'CPU Usage', color: 'red' }
}

// ✅ Display keys lead to clean tooltips
const categories = {
  'CPU Usage': { name: 'CPU Usage', color: 'red' }
}

Understanding Radius

In this component, the radius prop often controls the corner radius (segment rounding) rather than the outer radius of the chart.

  • Keep it small: Values between 2 and 8 provide a modern, rounded look.
  • Avoid large values: Setting radius to a high value (like 80 or 100 on a small chart) can distort the segments and break the tooltip interactive areas.

Controlling Size

To adjust the physical dimensions of the donut, use height and arcWidth instead of radius:

  • height: Controls the overall size of the SVG container.
  • arcWidth: Controls the thickness of the donut ring (and the size of the inner hole).

DonutType

Available donut chart types:

  • DonutType.Half or 'half' - Half donut chart
  • DonutType.Full or 'full' - Full donut chart (default)

Legend Positions

Available legend positions:

  • LegendPosition.TopRight - Top right of the chart
  • LegendPosition.BottomRight - Bottom right of the chart
  • LegendPosition.Left - Left of the chart
  • LegendPosition.Right - Right of the chart

Styling

The DonutChart component for Vue charts can be customized using CSS variables.

VariableDefaultDescription
--vis-donut-background-color#E7E9F3The background color of the donut chart.

Example:

:root {
  --vis-donut-background-color: transparent !important;
}

Examples

Check out examples here ↗