Donut Chart

Implement circular data visualizations with the Donut Chart component.

The DonutChart component provides a flexible and customizable way to visualize proportional data relationships in a circular format, supporting single and multiple segments with customizable colors and legends.

Basic Usage

Donut Chart with Legend

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.

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="80"
    :arc-width="20"
    :pad-angle="0.1"
  />
</template>

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