Donut Chart

Implement circular data visualizations with the Donut Chart component.

Basic Usage

Donut Chart with Legend

Props

PropTypeDefaultDescription
dataDonutChartData[][]Array of data points for the chart.
categoriesRecord<string, DonutCategory>{}Series configuration: name and color for each data key.
heightnumber300Height of the chart in pixels.
widthnumber300Width of the chart in pixels.
inner-radiusnumber0.6Inner radius ratio (0-1).
outer-radiusnumber1Outer radius ratio (0-1).
pad-anglenumber0Padding angle between segments in radians.
corner-radiusnumber0Corner radius for segments.
legend-positionLegendPosition'none'Position of the legend.
hide-legendbooleantrueHide the chart legend.
show-labelsbooleanfalseShow percentage labels on segments.
label-formatter(data: DonutChartData, key: string) => string-Function to format segment labels.
show-tooltipbooleantrueShow tooltip on hover.
tooltip-formatter(data: DonutChartData, key: string) => string-Custom formatter for tooltip content.

Data Format

The data should be an array of objects where each object represents a segment:

interface DonutChartData {
  category: string
  value: number
  [key: string]: string | number
}

Categories Format

Categories define the visual appearance for the chart:

interface DonutCategory {
  name: string
  color: string
}

interface DonutCategories {
  [key: string]: DonutCategory
}

Color Mapping

For multi-category donut charts, you can define colors for each segment:

multi-color-donut.vue
<script setup lang="ts">
const data = [
  { category: 'Desktop', value: 65 },
  { category: 'Mobile', value: 25 },
  { category: 'Tablet', value: 10 },
]

const categories = {
  desktop: { name: 'Desktop', color: '#3b82f6' },
  mobile: { name: 'Mobile', color: '#10b981' },
  tablet: { name: 'Tablet', color: '#f59e0b' },
}
</script>

<template>
  <DonutChart
    :data="data"
    :categories="categories"
    :height="300"
  />
</template>

Legend Positions

Available legend positions:

  • LegendPosition.Top - Above the chart
  • LegendPosition.Bottom - Below the chart
  • LegendPosition.Left - Left of the chart
  • LegendPosition.Right - Right of the chart
  • 'none' - No legend displayed