Arc

Chart.Arc draws one slice of a circle for each row. The angle of a slice shows the share of its value in the total. A pie chart is a chart with an arc mark. A donut chart is the same mark with a hole. Give inner, the radius of the hole as a fraction of the radius of the circle.

Energy of the city by source in 2025
sourceEnergy (GWh)%
Solar41237.9%
Wind29627.2%
Hydro23121.3%
Gas14813.6%

Anatomy

<script lang="ts">
	import { Chart } from '@human-kit/ui';
	import { scaleBand } from '@human-kit/ui/chart/scales/band';
</script>

<Chart.Root data={sources} x="source" y="energy" yLabel="Energy (GWh)" xScale={{ type: scaleBand }}>
	<Chart.Title>Energy by source</Chart.Title>
	<Chart.Plot>
		<Chart.Arc inner={0.6} />
	</Chart.Plot>
	<Chart.Legend />
	<Chart.Tooltip />
	<Chart.DataTable />
</Chart.Root>

The x channel gives the category of a slice, and the y channel gives its value. The categories are names, thus the x scale is a band scale, as on a bar chart. The mark makes a <g> with one group for the series. The group holds one <path> for each slice.

Order

The first slice starts at the top, and the slices go in the clockwise direction, in the order of the rows. The mark does not sort the rows. Sort them from the largest value to the smallest: then a user can compare the slices one after the other.

The circle is in the middle of the plot, and it fills the smaller side of the plot.

Values

  • A value of 0 makes a slice with no angle. It is still a point: the keyboard gets to it, and its name gives the share "0%".
  • A negative value, or a value that is not a number, makes no slice. In a development build, the mark writes a warning for a negative value.
  • When the total is 0, the names and the data table do not show a share.

The mark draws one series. Give it the rows of one series only.

Names

The name of a slice gives the category, the value and the share: "Solar, Energy (GWh) 412, 37.9%". The share has one decimal at most, in the locale of the chart. Thus the shares of a chart can have a sum that is not exactly 100%.

Labels

Give labels to show the value of each slice in the middle of the slice. A function of the point gives other text. A label that is wider than its slice does not show. The labels are for the eye only: the name of each slice already has the value.

Legend

Chart.Legend lists the categories of an arc mark in the order of the slices. Each item gets data-category, as each slice does. Thus one CSS rule gives a color to a slice and to its legend item.

Keyboard

ArrowRight and ArrowDown move to the next slice, in the clockwise direction. ArrowLeft and ArrowUp move to the previous slice. Home and End move to the first and the last slice. The keys do not wrap. The full table is on the Accessibility page.

Styles

Give each slice a color with the CSS color. The slices use it as their fill. A stroke in the color of the background keeps the slices apart. In the forced colors mode, all of the slices get one color, thus the stroke is necessary.

.chart [data-category='Solar'] {
	color: #2563eb;
}

.chart [data-mark='arc'] [data-point] {
	stroke: Canvas;
	stroke-width: 1;
}

.chart [data-mark='arc'] [data-point][data-focus-visible] {
	stroke: CanvasText;
	stroke-width: 2;
}

.chart [data-arc-label] {
	fill: white;
}
ElementAttributeWhen
Group of the markdata-markAlways. The value is arc.
Group of a seriesdata-seriesThe series has a name. The value is the name.
Slicedata-pointAlways.
Slice, labeldata-categoryAlways. The value is the category.
Slicedata-focusedThe slice has the focus.
Slicedata-focus-visibleThe slice has the focus, and the focus came from the keyboard.
Slicedata-selectedThe slice is selected.
Group of labelsdata-arc-labelslabels is set.
Labeldata-arc-labellabels is set.

API reference

Arc

An arc mark for pie and donut charts. It makes one <path> per row, a slice of a circle.

Prop Type Default

* required.

Data attribute Description
data-mark On the group of the mark. The value is arc.
data-series On the group of the series. The value is the name of the series.
data-category On each slice and each label. The value is the x value of the row.
data-arc-labels On the group of the labels.
data-arc-label On each label.
data-point On each point: a circle, a rect for a bar, or a path for a dot or a slice.
data-focused On the point that has the focus.
data-focus-visible On the focused point, when the focus came from the keyboard.
data-selected On the selected point. The point also has aria-current="true".