CwDonutChart

SVG donut with hover interaction, a center total and a legend. Segment colours come from the shared categorical chart palette, so they match the other charts in both themes.

Sizes

Default (200px)
Wheat: 340Corn: 280Soybeans: 190Cotton: 120Rice: 70
Larger and thinner
Wheat: 340Corn: 280Soybeans: 190Cotton: 120Rice: 70
No legend
Wheat: 340Corn: 280Soybeans: 190Cotton: 120Rice: 70
CwDonutChart example Copy code
<CwDonutChart {segments} size={280} thickness={30} />

<!-- Skeleton ring while loading; the no-data overlay shows automatically
     when segments are empty or add up to 0 -->
<CwDonutChart segments={data} loading={isLoading} />

Loading and no data

Loading
Empty segments

No data available

All values zero
Wheat: 0Corn: 0Soybeans: 0Cotton: 0Rice: 0

No data available

API

Usage and API reference

CwDonutChart renders proportional segment totals with hover feedback. Build the `segments` array first, then adjust chart size and thickness to fit the layout.

How to think about it

  1. Model your data as labeled totals Each segment needs a `label` and `value`, with optional `color` when the defaults are not enough.
  2. Tune size for the container Use `size` to fit the available space and `thickness` to control how heavy or airy the ring looks.
  3. Hide the legend only in cramped layouts The legend improves readability, so turn it off only when the surrounding UI already labels the segments.

Props and callbacks

APITypeDetails
segments Required
CwDonutSegment[]Chart segments to render.
size

Default: 200

numberSVG width and height in pixels.
thickness

Default: 40

numberRing stroke width in pixels.
showLegend

Default: true

booleanShows or hides the legend beneath the chart.
noData
string | booleanWhen present, blurs the chart and shows an overlay. Pass localized text, or use the bare `noData` attribute for "No data available".
segment.color
stringOptional per-segment CSS color override.
loading

Default: false

booleanShows a skeleton ring and sets `aria-busy` while data loads.
locale
stringBCP 47 locale for number and date formatting. Defaults to the runtime locale.
decimals
numberFixed number of fraction digits for displayed values.

Copy-paste examples

Each snippet is a complete, working example you can paste into a Svelte 5 component.

Default donut chart

The legend and center total are enabled by default.

Default donut chart Copy code
<script lang="ts">
	const segments = [
		{ label: 'Wheat', value: 340 },
		{ label: 'Corn', value: 280 },
		{ label: 'Soybeans', value: 190 }
	];
</script>

<CwDonutChart {segments} />
Compact chart with custom colors

Useful when you already label the categories elsewhere on the page.

Compact chart with custom colors Copy code
<script lang="ts">
	const storageSegments = [
		{ label: 'Free', value: 22, color: '#0f766e' },
		{ label: 'Reserved', value: 11, color: '#f59e0b' },
		{ label: 'Used', value: 67, color: '#dc2626' }
	];
</script>

<CwDonutChart
	segments={storageSegments}
	size={160}
	thickness={24}
	showLegend={false}
/>